Toggle button

A button that keeps a selected state and morphs between round and square when it changes.

When to use

Use a toggle button to switch a single option on or off, such as a filter or a favorite. The shape is part of the state: unselected buttons are round, selected buttons turn square.

Pick the shapes for the height with ToggleButtonDefaults.shapesFor so the pressed and checked shapes match the size.

Playground

The interactive page has a playground with live property controls for this component and generated code.

Examples

Types

All four types, toggle each one.

var a by rememberSaveable { mutableStateOf(true) }
var b by rememberSaveable { mutableStateOf(false) }
var c by rememberSaveable { mutableStateOf(false) }
var d by rememberSaveable { mutableStateOf(false) }

ToggleButton(checked = a, onCheckedChange = { a = it }) { Text("Filled") }
TonalToggleButton(checked = b, onCheckedChange = { b = it }) { Text("Tonal") }
ElevatedToggleButton(checked = c, onCheckedChange = { c = it }) { Text("Elevated") }
OutlinedToggleButton(checked = d, onCheckedChange = { d = it }) { Text("Outlined") }

Parameters

NameTypeDefaultDescription
checkedBooleanWhether the button is selected.
onCheckedChange(Boolean) -> UnitCalled with the requested new state.
shapesToggleButtonShapesToggleButtonDefaults.shapesFor(MinHeight)Resting, pressed and checked shapes. The button morphs between them.
colorsToggleButtonColorstoggleButtonColors()Container and content colors for checked and unchecked states.
contentPaddingPaddingValuescontentPaddingFor(MinHeight)Padding that matches the height.

Guidelines

Do:

Don't:

Accessibility

Related components