androidx.compose.material3

IconToggleButton

Composable function

An icon toggle button is an IconButton that stays on or off, like a favorite or bookmark button.

The button does not remember its state. You keep it in a variable and update it in onCheckedChange. To show the state, you can also change the icon, for example from an outlined to a filled heart.

Standard, filled, tonal and outlined; all checkedExpressive theme
Standard, filled, tonal and outlined; all checked
var on by remember { mutableStateOf(true) }
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
    IconToggleButton(checked = on, onCheckedChange = { on = it }) { Icon(Icons.Filled.Favorite, "Like") }
    FilledIconToggleButton(checked = on, onCheckedChange = { on = it }) { Icon(Icons.Filled.Favorite, "Like") }
    FilledTonalIconToggleButton(checked = on, onCheckedChange = { on = it }) { Icon(Icons.Filled.Favorite, "Like") }
    OutlinedIconToggleButton(checked = on, onCheckedChange = { on = it }) { Icon(Icons.Filled.Favorite, "Like") }
}

Basic

Takes one shape.

@Composable
fun IconToggleButton(
    checked: Boolean,
    onCheckedChange: (Boolean) -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: IconToggleButtonColors = IconButtonDefaults.iconToggleButtonColors(),
    interactionSource: MutableInteractionSource? = null,
    shape: Shape = IconButtonDefaults.standardShape,
    content: @Composable () -> Unit,
)

checked: BooleanRequired

Whether the button is on. Pass your state here.

onCheckedChange: (Boolean) -> UnitRequired

Called with the new value when the button is clicked. Update your state here.

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position. See the Modifier guide.

enabled: BooleanOptional

Default: true

Set to false to make the button gray and not clickable.

colors: IconToggleButtonColorsOptional

Default: IconButtonDefaults.iconToggleButtonColors()

Sets colors for on, off and disabled. Make one with IconButtonDefaults.iconToggleButtonColors. Each type has its own function.

interactionSource: MutableInteractionSource?Optional

Default: null

Lets you observe or control press, hover and focus states. Leave it null unless your code must react to them. See InteractionSource.

shape: ShapeOptionalSince 1.9

Default: IconButtonDefaults.standardShape

Sets the outline. Default: round.

content: @Composable () -> UnitRequired

The icon. Set a contentDescription on the Icon.

Expressive

Takes shapes: separate shapes for rest, pressed and checked.

@Composable
fun IconToggleButton(
    checked: Boolean,
    onCheckedChange: (Boolean) -> Unit,
    shapes: IconToggleButtonShapes,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: IconToggleButtonColors = IconButtonDefaults.iconToggleButtonVibrantColors(),
    interactionSource: MutableInteractionSource? = null,
    content: @Composable () -> Unit,
)

shapes: IconToggleButtonShapesRequiredSince 1.10

Sets shapes for rest, pressed and checked. Make one with IconButtonDefaults.toggleableShapes.

Same as above: checked, onCheckedChange, modifier, enabled, colors, interactionSource, content.

Icon toggle button types