Switches toggle the state of a single item on or off.
SwitchSample
@Composable
fun SwitchSample() {
val checkedState = remember { mutableStateOf(true) }
Switch(checked = checkedState.value, onCheckedChange = { checkedState.value = it })
var pineappleOnPizza by remember { mutableStateOf(true) }
Row(
Modifier.padding(16.dp)
.toggleable(
role = Role.Switch,
value = pineappleOnPizza,
onValueChange = { pineappleOnPizza = it },
)
) {
Switch(checked = pineappleOnPizza, onCheckedChange = null)
Spacer(Modifier.width(8.dp))
Text("Pineapple on pizza?")
}
}