Composable Component

Switch

Switch provides an animated switch for use as a toggle control in ToggleChip or SplitToggleChip.

Switch provides an animated switch for use as a toggle control in ToggleChip or SplitToggleChip.

Switch

Android
@Composable
public fun Switch(
    checked: Boolean,
    modifier: Modifier = Modifier,
    colors: SwitchColors = SwitchDefaults.colors(),
    enabled: Boolean = true,
    onCheckedChange: ((Boolean) -> Unit)? = null,
    interactionSource: MutableInteractionSource? = null,
): Unit

Parameters

checked Boolean flag indicating whether this switch is currently toggled on.
modifier Modifier to be applied to the switch. This can be used to provide a content description for accessibility.
colors SwitchColors from which the colors of the thumb and track will be obtained.
enabled Boolean flag indicating the enabled state of the Switch (affects the color).
onCheckedChange Callback to be invoked when Switch is clicked. If null, then this is passive and relies entirely on a higher-level component to control the state (such as ToggleChip or SplitToggleChip).
interactionSource When also providing onCheckedChange, an optional hoisted MutableInteractionSource for observing and emitting Interactions for this switch. You can use this to change the switch's appearance or preview the switch in different states. Note that if null is provided, interactions will still happen internally.