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
| Parameter | Type | Default | Description |
|---|---|---|---|
checked | Boolean | — | Whether 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. |
modifier | Modifier | Modifier | Modifier applied to the switch container. |
enabled | Boolean | true | When false, the toggle is non-interactive and all colors render at 50% opacity. |
colors | SwitchStyle | SwitchDefaults.colors() | Color tokens for both checked and unchecked states — see SwitchStyle. |
SwitchStyle
| Field | Type | Description |
|---|---|---|
checkedTrack | Color | Track fill color when the switch is on. |
checkedBorder | Color | Track border color when the switch is on. |
checkedThumb | Color | Thumb color when the switch is on. |
uncheckedTrack | Color | Track fill color when the switch is off. |
uncheckedBorder | Color | Track border color when the switch is off. |
uncheckedThumb | Color | Thumb color when the switch is off. |
SwitchDefaults
| Member | Description |
|---|---|
colors(): SwitchStyle | Returns 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.toggleablewithRole.Switchfor correct accessibility semantics. - Passing
onCheckedChange = nullrenders a read-only switch that cannot be interacted with (distinct fromenabled = false, which also applies opacity).