Last active
November 27, 2024 02:46
-
-
Save benigumocom/8216bf10df916ad3e2cb32769ff08091 to your computer and use it in GitHub Desktop.
Jetpack Compose Material3 SettingsScreen https://android.benigumo.com/20241127/jetpack-compose-material3-listitem/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun SettingsScreen( | |
modifier: Modifier = Modifier, | |
viewModel: SettingsViewModel = hiltViewModel() | |
) { | |
val on = viewModel.on.collectAsState() | |
LazyColumn{ | |
items(10) { | |
OutlinedCard( | |
modifier = modifier.padding(horizontal = 16.dp, vertical = 8.dp) | |
) { | |
Text( | |
text = "Network", | |
modifier = modifier.padding(16.dp), | |
) | |
// clickable | |
ListItem( | |
headlineContent = { Text("Advanced tracking") }, | |
modifier = modifier.clickable { Timber.d("clicked.") }, | |
leadingContent = { | |
Icon(Icons.Filled.Wifi, contentDescription = "Wifi",) | |
}, | |
trailingContent = { | |
Icon(Icons.Filled.ChevronRight, contentDescription = "Click") | |
} | |
) | |
HorizontalDivider() | |
// switch | |
ListItem( | |
headlineContent = { Text("Advanced tracking") }, | |
leadingContent = { | |
Icon(Icons.Filled.Wifi, contentDescription = "Wifi",) | |
}, | |
trailingContent = { | |
Switch(checked = on.value, onCheckedChange = { viewModel.toggle() }) | |
} | |
) | |
HorizontalDivider() | |
// checkbox | |
ListItem( | |
headlineContent = { Text("Advanced tracking") }, | |
leadingContent = { | |
Icon(Icons.Filled.Wifi, contentDescription = "Wifi",) | |
}, | |
trailingContent = { | |
Checkbox(checked = on.value, onCheckedChange = { viewModel.toggle() }) | |
} | |
) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Jetpack Compose Material3 の ListItem で設定画面を秒でつくる
https://android.benigumo.com/20241127/jetpack-compose-material3-listitem/