by @alexstyl
✉️ Leave your feedback

← Back to Wear Material Core

SplitToggleButton

Component
in
Wear Material Core
. Since 1.3.0-alpha06

Overview

Examples

Community Notes

Video

The SplitToggleButton offers three slots and a specific layout for a label, secondaryLabel and selection control. The secondaryLabel is optional. The items are laid out with a column containing the two label slots and a slot for the selection control at the end.

A SplitToggleButton has two tappable areas, one tap area for the labels and another for the selection control. The onClick listener will be associated with the main body of the SplitToggleButton with the onCheckedChange listener associated with the selection control area only.

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

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

@param checked Boolean flag indicating whether this button is currently checked. @param onCheckedChange Callback to be invoked when this buttons checked/selected status is changed. @param label A slot for providing the SplitToggleButton's main label. The contents are expected to be text which is "start" aligned. @param onClick Click listener called when the user clicks the main body of the SplitToggleButton, the area behind the labels. @param selectionControl A slot for providing the SplitToggleButton's selection controls(s). @param modifier Modifier to be applied to the SplitToggleButton @param secondaryLabel A slot for providing the SplitToggleButton's secondary label. The contents are expected to be "start" or "center" aligned. label and secondaryLabel contents should be consistently aligned. @param backgroundColor Composable lambda from which the backgroundColor will be obtained. @param splitBackgroundColor Composable lambda from which the splitBackgroundOverlay will be obtained. @param enabled Controls the enabled state of the SplitToggleButton. When false, this SplitToggleButton will not be clickable @param checkedInteractionSource The MutableInteractionSource representing the stream of Interactions for this SplitToggleButton'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 SplitToggleButton in different Interactions. @param clickInteractionSource The MutableInteractionSource representing the stream of Interactions for this SplitToggleButton's "clickable" 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 SplitToggleButton in different Interactions. @param contentPadding The spacing values to apply internally between the container and the content @param shape Defines the SplitToggleButton's shape. It is strongly recommended to use the default as this shape is a key characteristic of the Wear Material Theme

Overloads

SplitToggleButton

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@Composable
fun SplitToggleButton(
    checked: Boolean,
    onCheckedChange: (Boolean) -> Unit,
    label: @Composable RowScope.() -> Unit,
    onClick: () -> Unit,
    selectionControl: @Composable BoxScope.() -> Unit,
    modifier: Modifier,
    secondaryLabel: @Composable (RowScope.() -> Unit)?,
    backgroundColor: @Composable (enabled: Boolean, checked: Boolean) -> State<Color>,
    splitBackgroundColor: @Composable (enabled: Boolean, checked: Boolean) -> State<Color>,
    enabled: Boolean,
    checkedInteractionSource: MutableInteractionSource,
    clickInteractionSource: MutableInteractionSource,
    contentPadding: PaddingValues,
    shape: Shape
)

Parameters

NameDescription
checkedBoolean flag indicating whether this button is currently checked.
onCheckedChangeCallback to be invoked when this buttons checked/selected status is changed.
labelA slot for providing the SplitToggleButton'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 SplitToggleButton, the area behind the labels.
selectionControlA slot for providing the SplitToggleButton's selection controls(s).
modifierModifier to be applied to the SplitToggleButton
secondaryLabelA slot for providing the SplitToggleButton's secondary label. The contents are expected to be "start" or "center" aligned. label and secondaryLabel contents should be consistently aligned.
backgroundColorComposable lambda from which the backgroundColor will be obtained.
splitBackgroundColorComposable lambda from which the splitBackgroundOverlay will be obtained.
enabledControls the enabled state of the SplitToggleButton. When false, this SplitToggleButton will not be clickable
checkedInteractionSourceThe MutableInteractionSource representing the stream of Interactions for this SplitToggleButton'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 SplitToggleButton in different Interactions.
clickInteractionSourceThe MutableInteractionSource representing the stream of Interactions for this SplitToggleButton's "clickable" 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 SplitToggleButton in different Interactions.
contentPaddingThe spacing values to apply internally between the container and the content
shapeDefines the SplitToggleButton's shape. It is strongly recommended to use the default as this shape is a key characteristic of the Wear Material Them
Previous ComponentRadioButton
Next ComponentStepper