New Compose Multiplatform components arrived on Composables UICheck it out →

SplitToggleButton

The Wear Material [SplitToggleButton] 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.

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

A [SplitToggleButton] 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 button with the [onCheckedChange] listener associated with the toggle control area only.

Last updated:

Installation

dependencies {
   implementation("androidx.wear.compose:compose-material3:1.0.0-alpha23")
}

Overloads

@Composable
fun SplitToggleButton(
    checked: Boolean,
    onCheckedChange: (Boolean) -> Unit,
    onClick: () -> Unit,
    toggleControl: @Composable ToggleControlScope.() -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    shape: Shape = SplitToggleButtonTokens.ContainerShape.value,
    colors: SplitToggleButtonColors = ToggleButtonDefaults.splitToggleButtonColors(),
    checkedInteractionSource: MutableInteractionSource? = null,
    clickInteractionSource: MutableInteractionSource? = null,
    contentPadding: PaddingValues = ToggleButtonDefaults.ContentPadding,
    secondaryLabel: @Composable (RowScope.() -> Unit)? = null,
    label: @Composable RowScope.() -> Unit
)

Parameters

namedescription
checkedBoolean flag indicating whether this button is currently checked.
onCheckedChangeCallback to be invoked when this buttons checked status is changed.
onClickClick listener called when the user clicks the main body of the button, the area behind the labels.
toggleControlA slot for providing the button's toggle control. Two built-in types of toggle control are supported: [Checkbox] and [Switch].
modifierModifier to be applied to the button.
enabledControls the enabled state of the button. When false, this button will not be clickable.
shapeDefines the button's shape. It is strongly recommended to use the default as this shape is a key characteristic of the Wear Material Theme.
colors[SplitToggleButtonColors] that will be used to resolve the background and content color for this button in different states.
contentPaddingThe spacing values to apply internally between the container and the content.
checkedInteractionSourcean optional hoisted [MutableInteractionSource] for observing and emitting [Interaction]s for this button's "toggleable" tap area. You can use this to change the button's appearance or preview the button 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 button's "clickable" tap area. You can use this to change the button's appearance or preview the button in different states. Note that if null is provided, interactions will still happen internally.
secondaryLabelA slot for providing the button's secondary label. The contents are expected to be "start" aligned.
labelA slot for providing the button's main label. The contents are expected to be text which is "start" aligned.

Code Examples

SplitToggleButtonWithCheckbox

@Composable
@Sampled
fun SplitToggleButtonWithCheckbox() {
    var checked by remember { mutableStateOf(true) }
    SplitToggleButton(
        label = {
            Text("Split with CheckboxIcon", maxLines = 3, overflow = TextOverflow.Ellipsis)
        },
        checked = checked,
        toggleControl = { Checkbox() },
        onCheckedChange = { checked = it },
        onClick = {
            /* Do something */
        },
        enabled = true,
    )
}

SplitToggleButtonWithSwitch

@Composable
@Sampled
fun SplitToggleButtonWithSwitch() {
    var checked by remember { mutableStateOf(true) }
    SplitToggleButton(
        label = {
            Text("Split with CheckboxIcon", maxLines = 3, overflow = TextOverflow.Ellipsis)
        },
        checked = checked,
        toggleControl = { Switch() },
        onCheckedChange = { checked = it },
        onClick = {
            /* Do something */
        },
        enabled = true,
    )
}