← Back to Material Compose
Switch
Component
in
Material
. Since 0.1.0-dev15
Overview
Examples
Community Notes
<a href="https://material.io/components/switches" class="external" target="_blank">Material Design switch</a>.
Switches toggle the state of a single item on or off.
!Switches image(https://developer.android.com/images/reference/androidx/compose/material/switches.png)
Overloads
Switch
@Composable
@OptIn(ExperimentalMaterialApi::class)
fun Switch(
checked: Boolean,
onCheckedChange: ((Boolean) -> Unit)?,
modifier: Modifier = Modifier,
enabled: Boolean = true,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
colors: SwitchColors = SwitchDefaults.colors()
)
Parameters
Name | Description |
---|---|
checked | whether or not this component is checked |
onCheckedChange | callback to be invoked when Switch is being clicked, therefore the change of checked state is requested. If null, then this is passive and relies entirely on a higher-level component to control the "checked" state. |
modifier | Modifier to be applied to the switch layout |
enabled | whether the component is enabled or grayed out |
interactionSource | the MutableInteractionSource representing the stream of Interactions for this Switch. You can create and pass in your own remembered MutableInteractionSource if you want to observe Interactions and customize the appearance / behavior of this Switch in different Interactions. |
colors | SwitchColors that will be used to determine the color of the thumb and track in different states. See SwitchDefaults.colors |
Previous Component← SwipeToDismiss
Next ComponentTab →
