Jetpack Compose - Checkbox

Checkboxes allow users to select one or more items from a set. Checkboxes can turn an option on or off.
  • Unchecked Check Box,
  • Checked Check Box,
  • Color Check Box,
  • Grouped Check Box



  • Unchecked Check Box

val isChecked = remember { mutableStateOf(false) }
Checkbox(
checked = isChecked.value,
onCheckedChange = {
isChecked.value = it
},
)
Spacer(modifier = Modifier.size(16.dp))
Text("A")

  • Checked Check Box

val isChecked = remember { mutableStateOf(true) }
Checkbox(
checked = isChecked.value,
onCheckedChange = {
isChecked.value = it
},
)
Spacer(modifier = Modifier.size(16.dp))
Text("B")

  • Color Check Box

val isChecked = remember { mutableStateOf(true) }
Checkbox(
checked = isChecked.value,
onCheckedChange = {
isChecked.value = it
},
colors = CheckboxDefaults.colors(androidx.compose.ui.graphics.Color.Red)
)
Spacer(modifier = Modifier.size(16.dp))
Text("Color")

  • Grouped Check Box
  val fruitsList = arrayListOf("Apple", "Mango", "Orange")
fruitsList.forEach { option: String ->
Spacer(modifier = Modifier.size(16.dp))
Row(
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
) {
val isChecked = remember { mutableStateOf(false) }
Checkbox(
checked = isChecked.value,
onCheckedChange = {
isChecked.value = it
}
)
Spacer(modifier = Modifier.size(16.dp))
Text(option)
}


.. 


Comments