← Compose Multiplatform Component in Wear Material 3 Compose
SplitRadioButton
The Wear Material [SplitRadioButton] 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.
The [SplitRadioButton] 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 [SplitRadioButton] height adjusts to accommodate the contents. The label and secondary label should be consistently aligned.
A [SplitRadioButton] 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 split radio button with the [onSelect] listener associated with the selection control area only.
Last updated:
Installation
dependencies {
implementation("androidx.wear.compose:compose-material3:1.0.0-alpha23")
}
Overloads
@Composable
fun SplitRadioButton(
selected: Boolean,
onSelect: () -> Unit,
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
selectionControl: @Composable SelectionControlScope.() -> Unit = {
Radio()
},
shape: Shape = SplitRadioButtonTokens.Shape.value,
colors: SplitRadioButtonColors = RadioButtonDefaults.splitRadioButtonColors(),
selectionInteractionSource: MutableInteractionSource? = null,
clickInteractionSource: MutableInteractionSource? = null,
contentPadding: PaddingValues = RadioButtonDefaults.ContentPadding,
secondaryLabel: @Composable (RowScope.() -> Unit)? = null,
label: @Composable RowScope.() -> Unit
)
Parameters
name | description |
---|---|
selected | Boolean flag indicating whether this button is currently selected. |
onSelect | Callback to be invoked when this button has been selected by clicking. |
onClick | Click listener called when the user clicks the main body of the button, the area behind the labels. |
selectionControl | A slot for providing the button's selection control. The [Radio] selection control is provided for this purpose. |
modifier | Modifier to be applied to the button. |
enabled | Controls the enabled state of the button. When false , this button will not be clickable. |
shape | Defines 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 | [SplitRadioButtonColors] that will be used to resolve the background and content color for this button in different states. |
contentPadding | The spacing values to apply internally between the container and the content. |
selectionInteractionSource | an optional hoisted [MutableInteractionSource] for observing and emitting [Interaction]s for this button's "selectable" 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. |
clickInteractionSource | an 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. |
secondaryLabel | A slot for providing the button's secondary label. The contents are expected to be "start" aligned. |
label | A slot for providing the button's main label. The contents are expected to be text which is "start" aligned. |
Code Example
SplitRadioButton
@Composable
@Sampled
fun SplitRadioButton() {
Column(modifier = Modifier.selectableGroup()) {
var selectedButton by remember { mutableStateOf(0) }
// SplitRadioButton uses the Radio selection control by default.
SplitRadioButton(
label = {
Text("First Radio Button", maxLines = 3, overflow = TextOverflow.Ellipsis)
},
selected = selectedButton == 0,
onSelect = { selectedButton = 0 },
onClick = {
/* Do something */
},
enabled = true,
)
Spacer(modifier = Modifier.height(4.dp))
SplitRadioButton(
label = {
Text("Second Radio Button", maxLines = 3, overflow = TextOverflow.Ellipsis)
},
selected = selectedButton == 1,
onSelect = { selectedButton = 1 },
onClick = {
/* Do something */
},
enabled = true,
)
}
}