Switch

A control that allows the user to toggle between checked and not checked.

Basic Usage

Switch is a fully custom-drawn toggle (40×18 dp track, 16 dp thumb). The thumb slides and colors animate with a 150 ms tween on every state change.

Disabled

Set enabled = false to prevent interaction. Both the track and thumb are rendered at 50% opacity.

Custom Colors

Pass a SwitchStyle to colors to override any of the six color tokens for checked and unchecked states.

API Reference

Switch

ParameterTypeDefaultDescription
checkedBooleanWhether the switch is in the on state.
onCheckedChange((Boolean) -> Unit)?Callback invoked with the new state when toggled. Pass null to make the switch non-interactive.
modifierModifierModifierModifier applied to the switch container.
enabledBooleantrueWhen false, the toggle is non-interactive and all colors render at 50% opacity.
colorsSwitchStyleSwitchDefaults.colors()Color tokens for both checked and unchecked states — see SwitchStyle.

SwitchStyle

FieldTypeDescription
checkedTrackColorTrack fill color when the switch is on.
checkedBorderColorTrack border color when the switch is on.
checkedThumbColorThumb color when the switch is on.
uncheckedTrackColorTrack fill color when the switch is off.
uncheckedBorderColorTrack border color when the switch is off.
uncheckedThumbColorThumb color when the switch is off.

SwitchDefaults

MemberDescription
colors(): SwitchStyleReturns the default SwitchStyle resolved from the current MaterialTheme. Checked state uses primary/primaryForeground; unchecked state uses input/primary.

Behaviour notes

  • The switch is entirely drawn with drawBehind — no Compose layout children are used for the track or thumb.
  • Thumb position, track color, border color, and thumb color each animate independently with a 150 ms tween.
  • The component uses Modifier.toggleable with Role.Switch for correct accessibility semantics.
  • Passing onCheckedChange = null renders a read-only switch that cannot be interacted with (distinct from enabled = false, which also applies opacity).
Edit this page on GitHub