androidx.compose.material3
ToggleButtonSince 1.10
Composable function
A toggle button is a Button that stays on or off, like "Bold" in a text editor. When checked, it changes color and shape.
The button does not remember its state. You keep it in a variable and update it in onCheckedChange.

val checked = remember { mutableStateListOf(true, false, false, false) }
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
ToggleButton(checked = checked[0], onCheckedChange = { checked[0] = it }) { Text("Filled") }
ElevatedToggleButton(checked = checked[1], onCheckedChange = { checked[1] = it }) { Text("Elevated") }
TonalToggleButton(checked = checked[2], onCheckedChange = { checked[2] = it }) { Text("Tonal") }
OutlinedToggleButton(checked = checked[3], onCheckedChange = { checked[3] = it }) { Text("Outlined") }
}
Toggle buttons are the pieces of a connected ButtonGroup.
Parameters
@Composable
fun ToggleButton(
checked: Boolean,
onCheckedChange: (Boolean) -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
shapes: ToggleButtonShapes = ToggleButtonDefaults.shapesFor(ButtonDefaults.MinHeight),
colors: ToggleButtonColors = ToggleButtonDefaults.toggleButtonColors(),
elevation: ButtonElevation? = ButtonDefaults.buttonElevation(),
border: BorderStroke? = null,
contentPadding: PaddingValues = ButtonDefaults.contentPaddingFor(ButtonDefaults.MinHeight),
interactionSource: MutableInteractionSource? = null,
content: @Composable RowScope.() -> Unit,
)
checked: BooleanRequired
checked: BooleanRequiredWhether the button is on. Pass your state here.
onCheckedChange: (Boolean) -> UnitRequired
onCheckedChange: (Boolean) -> UnitRequiredCalled with the new value when the button is clicked. Update your state here.
modifier: ModifierOptional
modifier: ModifierOptionalDefault: Modifier
Changes size, padding, or position. See the Modifier guide.
enabled: BooleanOptional
enabled: BooleanOptionalDefault: true
Set to false to make the button gray and not clickable.
shapes: ToggleButtonShapesOptional
shapes: ToggleButtonShapesOptionalDefault: ToggleButtonDefaults.shapesFor(ButtonDefaults.MinHeight)
Sets three shapes: at rest, pressed and checked. Make one with ToggleButtonDefaults.shapes.
Default: round at rest, square when checked.
colors: ToggleButtonColorsOptional
colors: ToggleButtonColorsOptionalDefault: ToggleButtonDefaults.toggleButtonColors()
Sets colors for on, off and disabled. Make one with ToggleButtonDefaults.toggleButtonColors. Each type has its own function.
elevation: ButtonElevation?Optional
elevation: ButtonElevation?OptionalDefault: ButtonDefaults.buttonElevation()
Sets the shadow height. Pass null for no shadow.
border: BorderStroke?Optional
border: BorderStroke?OptionalDefault: null
Draws an outline. OutlinedToggleButton has one by default.
contentPadding: PaddingValuesOptional
contentPadding: PaddingValuesOptionalDefault: ButtonDefaults.contentPaddingFor(ButtonDefaults.MinHeight)
Space between the edge of the button and the content.
interactionSource: MutableInteractionSource?Optional
interactionSource: MutableInteractionSource?OptionalDefault: null
Lets you observe or control press, hover and focus states. Leave it null unless your code must react to them. See InteractionSource.
content: @Composable RowScope.() -> UnitRequired
content: @Composable RowScope.() -> UnitRequiredWhat the button shows. Usually a Text, sometimes an Icon and a Text. Placed in a Row.

var starred by remember { mutableStateOf(true) }
ToggleButton(checked = starred, onCheckedChange = { starred = it }) {
Icon(Icons.Filled.Star, contentDescription = null, Modifier.size(ToggleButtonDefaults.IconSize))
Spacer(Modifier.size(ToggleButtonDefaults.IconSpacing))
Text(if (starred) "Starred" else "Star")
}
Toggle button types
See also
ToggleButtonDefaults: default values and helper functions forToggleButton.