Skip to content

Switch

@Composable



fun Switch(
    checked: Boolean, 
    onCheckedChange: (Boolean) -> Unit, 
    modifier: Modifier = Modifier, 
    enabled: Boolean = true, 
    trackTexture: String = "switch_track", 
    thumbTexture: String = "switch_thumb", 
    variant: String = ThemeVariants.DEFAULT
)

Simple styled switch control suitable for toggling boolean settings.

Renders the themed trackTexture state - a combined checked+hovered state is used when both apply and the theme defines it - with the themed thumbTexture drawn on top, animating between its off/on positions.

Parameters

  • checked: The current checked state.

  • onCheckedChange: Called with the new checked value when the user clicks.

  • modifier: Additional modifiers applied to the outer container.

  • enabled: When false, pointer events are ignored and the TextureStates.DISABLED state is shown.

  • trackTexture: The themed texture key for the track, looked up via LocalTheme.

  • thumbTexture: The themed texture key for the thumb, looked up via LocalTheme.

  • variant: The theme variant of both textures to use. See ThemeVariants.