API reference

Switch Composable

Displays an immediate-effect toggle for an on/off setting.

Signature

@Composable
fun Switch(
    checked: Boolean,
    onCheckedChange: (Boolean) -> Unit?,
    modifier: Modifier = Modifier,
    contentDescription: String? = null,
    thumbContent: @Composable () -> Unit? = null,
    enabled: Boolean = true,
    colors: SwitchColors = SwitchDefaults.Colors,
    dimensions: ControlDimensions = UiSetTheme.dimensions.controls,
    shape: Shape = UiSetTheme.shapes.pill,
    thumbShape: Shape = UiSetTheme.shapes.pill,
    indication: UiSetIndicationSpec? = UiSetTheme.indications.standard.default,
)

Parameters

checked: Boolean whether the setting is on
onCheckedChange: ((Boolean) -> Unit)? callback receiving the requested state, or null when a parent owns the interaction semantics
modifier: Modifier modifier applied to the 48dp interaction target
contentDescription: String? accessibility label when no external label describes the switch
thumbContent: (@Composable () -> Unit)? optional icon or custom content inside the thumb
enabled: Boolean whether the switch accepts input
colors: SwitchColors colors for checked, unchecked, and disabled states
dimensions: ControlDimensions track, thumb, border, and mark values; switchHeight must be at least visualSize, and switchWidth must be at least switchHeight
shape: Shape visual track shape
thumbShape: Shape visual thumb shape
indication: UiSetIndicationSpec? interaction feedback split around the track clipping boundary

Throws

IllegalArgumentException when dimensions does not satisfy those constraints