State of Compose 2023 results are in! Click here to learn more

← Back to Wear Material

ToggleChip

Component
in
Wear Material
. Since 1.0.0

Overview

Code Examples

Video

A ToggleChip is a specialized type of Chip that includes a slot for a bi-state toggle control such as a radio button, toggle or checkbox.

The Wear Material ToggleChip offers four slots and a specific layout for an application icon, a label, a secondaryLabel and toggle control. The application icon and secondaryLabel are optional. The items are laid out in a row with the optional icon at the start, a column containing the two label slots in the middle and a slot for the toggle control at the end.

The ToggleChip is Stadium shaped and has a max height designed to take no more than two lines of text of Typography.button style. With localisation and/or large font sizes, the ToggleChip height adjusts to accommodate the contents. The label and secondary label should be consistently aligned.

The recommended set of ToggleChipColors can be obtained from ToggleChipDefaults, e.g. ToggleChipDefaults.toggleChipColors.

Chips can be enabled or disabled. A disabled chip will not respond to click events.

Example of a ToggleChip with an icon, label and secondary label (defaults to switch toggle):

Overloads

ToggleChip

@Composable
public fun ToggleChip(
    checked: Boolean,
    onCheckedChange: (Boolean) -> Unit,
    label: @Composable RowScope.() -> Unit,
    toggleControl: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    appIcon: @Composable (BoxScope.() -> Unit)? = null,
    secondaryLabel: @Composable (RowScope.() -> Unit)? = null,
    colors: ToggleChipColors = ToggleChipDefaults.toggleChipColors(),
    enabled: Boolean = true,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    contentPadding: PaddingValues = ToggleChipDefaults.ContentPadding,
    shape: Shape = MaterialTheme.shapes.small,
)

Parameters

NameDescription
checkedBoolean flag indicating whether this button is currently checked.
onCheckedChangeCallback to be invoked when this buttons checked/selected status changes
labelA slot for providing the chip's main label. The contents are expected to be text which is "start" aligned.
toggleControlA slot for providing the chip's toggle controls(s). The contents are expected to be a horizontally and vertically centre aligned icon of size ToggleChipDefaults.IconSize. Three built-in types of toggle control are supported and ImageVectors can be obtained from ToggleChipDefaults.switchIcon, ToggleChipDefaults.radioIcon and ToggleChipDefaults.checkboxIcon. In order to correctly render when the Chip is not enabled the icon must set its alpha value to LocalContentAlpha.
modifierModifier to be applied to the chip
appIconAn optional slot for providing an icon to indicate the purpose of the chip. The contents are expected to be a horizontally and vertically centre aligned icon of size ToggleChipDefaults.IconSize. In order to correctly render when the Chip is not enabled the icon must set its alpha value to LocalContentAlpha.
secondaryLabelA slot for providing the chip's secondary label. The contents are expected to be text which is "start" aligned if there is an icon preset and "start" or "center" aligned if not. label and secondaryLabel contents should be consistently aligned.
colorsToggleChipColors that will be used to resolve the background and content color for this chip in different states, see ToggleChipDefaults.toggleChipColors.
enabledControls the enabled state of the chip. When false, this chip will not be clickable
interactionSourceThe MutableInteractionSource representing the stream of Interactions for this chip's "toggleable" tap area. You can create and pass in your own remembered MutableInteractionSource if you want to observe Interactions and customize the appearance / behavior of this Chip in different Interactions.
contentPaddingThe spacing values to apply internally between the container and the content
shapeDefines the chip's shape. It is strongly recommended to use the default as this shape is a key characteristic of the Wear Material Them