← Back to Wear Material Core
SplitToggleButton
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
Name | Description |
---|---|
checked | Boolean flag indicating whether this button is currently checked. |
onCheckedChange | Callback to be invoked when this buttons checked/selected status is changed. |
label | A slot for providing the SplitToggleButton's main label. The contents are expected to be text which is "start" aligned. |
onClick | Click listener called when the user clicks the main body of the SplitToggleButton, the area behind the labels. |
selectionControl | A slot for providing the SplitToggleButton's selection controls(s). |
modifier | Modifier to be applied to the SplitToggleButton |
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. |
backgroundColor | Composable lambda from which the backgroundColor will be obtained. |
splitBackgroundColor | Composable lambda from which the splitBackgroundOverlay will be obtained. |
enabled | Controls the enabled state of the SplitToggleButton. When false , this SplitToggleButton will not be clickable |
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. |
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. |
contentPadding | The spacing values to apply internally between the container and the content |
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 Them |