androidx.compose.material3
Switch
Composable function
A switch turns one setting on or off. The change takes effect right away.
The switch does not remember its state. You keep it in a variable and update it in onCheckedChange.

var on by remember { mutableStateOf(true) }
Switch(checked = on, onCheckedChange = { on = it })

Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
Switch(checked = true, onCheckedChange = {})
Switch(checked = false, onCheckedChange = {})
Switch(checked = true, onCheckedChange = {}, enabled = false)
Switch(checked = false, onCheckedChange = {}, enabled = false)
}
Parameters
@Composable
fun Switch(
checked: Boolean,
onCheckedChange: ((Boolean) -> Unit)?,
modifier: Modifier = Modifier,
thumbContent: (@Composable () -> Unit)? = null,
enabled: Boolean = true,
colors: SwitchColors = SwitchDefaults.colors(),
interactionSource: MutableInteractionSource? = null,
)
checked: BooleanRequired
checked: BooleanRequiredWhether the switch is on. Pass your state here.
onCheckedChange: ((Boolean) -> Unit)?Required
onCheckedChange: ((Boolean) -> Unit)?RequiredCalled with the new value when the user flips the switch. Update your state here.
Pass null if the switch should not react, for example when a whole row handles the click.
modifier: ModifierOptional
modifier: ModifierOptionalDefault: Modifier
Changes size, padding, or position of the switch. See the Modifier guide.
To make a label clickable too, put both in a Row and give the Row a Modifier.toggleable.

var wifi by remember { mutableStateOf(true) }
Row(
modifier = Modifier.toggleable(value = wifi, onValueChange = { wifi = it }, role = Role.Switch),
verticalAlignment = Alignment.CenterVertically,
) {
Text("Wi-Fi", Modifier.width(200.dp))
// The Row handles clicks, so the switch itself does not.
Switch(checked = wifi, onCheckedChange = null)
}
thumbContent: (@Composable () -> Unit)?Optional
thumbContent: (@Composable () -> Unit)?OptionalDefault: null
Something drawn inside the thumb, usually an Icon.
Size the icon with SwitchDefaults.IconSize.

var on by remember { mutableStateOf(true) }
Switch(
checked = on,
onCheckedChange = { on = it },
thumbContent = if (on) {
{ Icon(Icons.Filled.Check, contentDescription = null, Modifier.size(SwitchDefaults.IconSize)) }
} else null,
)
enabled: BooleanOptional
enabled: BooleanOptionalDefault: true
Set to false to make the switch gray and not clickable.
colors: SwitchColorsOptional
colors: SwitchColorsOptionalDefault: SwitchDefaults.colors()
Sets the thumb, track, border and icon colors for every state.
Make one with SwitchDefaults.colors. Pass only the colors you want to change.

Switch(
checked = true,
onCheckedChange = {},
colors = SwitchDefaults.colors(
checkedThumbColor = MaterialTheme.colorScheme.onTertiary,
checkedTrackColor = MaterialTheme.colorScheme.tertiary,
),
)
interactionSource: MutableInteractionSource?Optional
interactionSource: MutableInteractionSource?OptionalDefault: null
Lets you observe or control press, hover and focus states. Leave it null unless your code must react to them. See InteractionSource.
See also
SwitchDefaults: default values and helper functions forSwitch.