We just launched Compose Examples featuring over 150+ components! Check it out →

SplitToggleChip

Android

Component in Wear Material Compose

A [SplitToggleChip] is a specialized type of [Chip] that includes a slot for a toggle control, such as a toggle or checkbox. The [SplitToggleChip] differs from the [ToggleChip] by having two "tappable" areas, one clickable and one toggleable.

This overload provides suitable accessibility semantics for a toggleable control like [Checkbox] and [Switch]. For selectable controls like [RadioButton], use [SelectableChip] instead.

The Wear Material [SplitToggleChip] offers three slots and a specific layout for a label, secondaryLabel and toggle control. The secondaryLabel is optional. The items are laid out with a column containing the two label slots and a slot for the toggle control at the end.

A [SplitToggleChip] has two tappable areas, one tap area for the labels and another for the toggle control. The [onClick] listener will be associated with the main body of the split toggle chip with the [onCheckedChange] listener associated with the toggle control area only.

For a split toggle chip the background of the tappable background area behind the toggle control will have a visual effect applied to provide a "divider" between the two tappable areas.

The [SplitToggleChip] 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 [SplitToggleChip] height adjusts to accommodate the contents. The label and secondary label should be consistently aligned.

The recommended set of [SplitToggleChipColors] can be obtained from [ToggleChipDefaults], e.g. [ToggleChipDefaults.splitToggleChipColors].

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

Last updated:

Installation

dependencies {
   implementation("androidx.wear.compose:compose-material:1.5.0-alpha04")
}

Overloads

@Composable
fun SplitToggleChip(
    checked: Boolean,
    onCheckedChange: (Boolean) -> Unit,
    label: @Composable RowScope.() -> Unit,
    onClick: () -> Unit,
    toggleControl: @Composable BoxScope.() -> Unit,
    modifier: Modifier = Modifier,
    secondaryLabel: @Composable (RowScope.() -> Unit)? = null,
    colors: SplitToggleChipColors = ToggleChipDefaults.splitToggleChipColors(),
    enabled: Boolean = true,
    checkedInteractionSource: MutableInteractionSource? = null,
    clickInteractionSource: MutableInteractionSource? = null,
    contentPadding: PaddingValues = ToggleChipDefaults.ContentPadding,
    shape: Shape = MaterialTheme.shapes.large,
)

Parameters

namedescription
checkedBoolean flag indicating whether this button is currently checked.
onCheckedChangeCallback to be invoked when this buttons checked status is changed.
labelA slot for providing the chip's main label. The contents are expected to be text which is "start" aligned.
onClickClick listener called when the user clicks the main body of the chip, the area behind the labels.
toggleControlA slot for providing the chip's toggle controls(s). Two built-in types of toggle control are supported, see [Checkbox] and [Switch]. For [RadioButton], use [SelectableChip] instead. [ImageVector]s 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
secondaryLabelA slot for providing the chip's secondary label. The contents are expected to be "start" or "center" aligned. label and secondaryLabel contents should be consistently aligned.
colors[SplitToggleChipColors] that will be used to resolve the background and content color for this chip in different states, see [ToggleChipDefaults.splitToggleChipColors].
enabledControls the enabled state of the chip. When false, this chip will not be clickable
checkedInteractionSourcean optional hoisted [MutableInteractionSource] for observing and emitting [Interaction]s for this chip's "toggleable" tap area. You can use this to change the chip's appearance or preview the chip in different states. Note that if null is provided, interactions will still happen internally.
clickInteractionSourcean optional hoisted [MutableInteractionSource] for observing and emitting [Interaction]s for this chip's "clickable" tap area. You can use this to change the chip's appearance or preview the chip in different states. Note that if null is provided, interactions will still happen internally.
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 Theme

Code Example

SplitToggleChipWithCheckbox

@Composable
fun SplitToggleChipWithCheckbox() {
    var checked by remember { mutableStateOf(true) }
    // The primary label should have a maximum 3 lines of text
    // and the secondary label should have max 2 lines of text.
    SplitToggleChip(
        label = { Text("Split with CheckboxIcon", maxLines = 3, overflow = TextOverflow.Ellipsis) },
        checked = checked,
        toggleControl = {
            Checkbox(
                checked = checked,
                enabled = true,
            )
        },
        onCheckedChange = { checked = it },
        onClick = {
            /* Do something */
        },
        enabled = true,
    )
}
by @alexstyl