Toggle Switch
fun ToggleSwitch(toggled: Boolean, modifier: Modifier = Modifier, onToggled: (Boolean) -> Unit? = null, enabled: Boolean = true, shape: Shape = RectangleShape, backgroundColor: Color = Color.Unspecified, contentPadding: PaddingValues = NoPadding, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, indication: Indication = LocalIndication.current, thumb: @Composable () -> Unit)
A foundational component used to build toggle switches.
For interactive preview & code examples, visit Toggle Switch Documentation.
Basic Example
var toggled by remember { mutableStateOf(false) }
ToggleSwitch(
toggled = toggled,
onToggled = { toggled = it },
backgroundColor = Color.Gray,
thumb = {
Box(
modifier = Modifier
.size(24.dp)
.background(Color.White, CircleShape)
)
}
)Content copied to clipboard
Parameters
toggled
Whether the switch is currently toggled on.
modifier
Modifier to be applied to the switch.
on Toggled
Callback that is called when the switch is toggled.
enabled
Whether the switch is enabled.
shape
The shape of the switch's track.
background Color
The background color of the switch's track.
content Padding
The padding to be applied to the switch's content.
interaction Source
The MutableInteractionSource that will be used to dispatch interaction events.
indication
The indication to be shown when the switch is interacted with.
thumb
The composable that represents the thumb of the switch.