Switch

Composable Component

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

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

checkedBoolean flag indicating whether this switch is currently toggled on.
modifierModifier to be applied to the switch. This can be used to provide a content description for accessibility.
colorsSwitchColors from which the colors of the thumb and track will be obtained.
enabledBoolean flag indicating the enabled state of the Switch (affects the color).
onCheckedChangeCallback 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).
interactionSourceWhen 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.