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

SplitRadioButton

Android

Component in Wear Material 3 Compose

The Wear Material [SplitRadioButton] offers two slots and a specific layout for a label and secondaryLabel. The secondaryLabel is optional. The items are laid out with a column containing the two label slots and radio button control at the end.

The [SplitRadioButton] is Stadium shaped. The label should take no more than 3 lines of text. The secondary label should take no more than 2 lines of text. With localisation and/or large font sizes, the [SplitRadioButton] height adjusts to accommodate the contents. The label and secondary label are start aligned by default.

A [SplitRadioButton] has two tappable areas, one tap area for the labels and another for the selection control. The [onContainerClick] listener will be associated with the main body of the split radio button with the [onSelectionClick] listener associated with the selection control area only.

Last updated:

Installation

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

Overloads

@Composable
fun SplitRadioButton(
    selected: Boolean,
    onSelectionClick: () -> Unit,
    selectionContentDescription: String?,
    onContainerClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    shape: Shape = RadioButtonDefaults.splitRadioButtonShape,
    colors: SplitRadioButtonColors = RadioButtonDefaults.splitRadioButtonColors(),
    selectionInteractionSource: MutableInteractionSource? = null,
    containerInteractionSource: MutableInteractionSource? = null,
    containerClickLabel: String? = null,
    contentPadding: PaddingValues = RadioButtonDefaults.ContentPadding,
    secondaryLabel: @Composable (RowScope.() -> Unit)? = null,
    label: @Composable RowScope.() -> Unit
)

Parameters

namedescription
selectedBoolean flag indicating whether this button is currently selected.
onSelectionClickCallback to be invoked when this button has been selected.
selectionContentDescriptionThe content description for the selection control part of the component
onContainerClickClick listener called when the user clicks the main body of the button, the area containing the labels.
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[SplitRadioButtonColors] 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.
selectionInteractionSourcean 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.
containerInteractionSourcean 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.
containerClickLabelOptional click label on the main body of the button for accessibility.
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 Example

SplitRadioButtonSample

@Composable
fun SplitRadioButtonSample() {
    Column(modifier = Modifier.selectableGroup()) {
        var selectedButton by remember { mutableStateOf(0) }
        // SplitRadioButton uses the Radio selection control by default.
        SplitRadioButton(
            label = { Text("First Button", maxLines = 3, overflow = TextOverflow.Ellipsis) },
            selected = selectedButton == 0,
            onSelectionClick = { selectedButton = 0 },
            selectionContentDescription = "First",
            onContainerClick = {
                /* Do something */
            },
            containerClickLabel = "click",
            enabled = true,
        )
        Spacer(modifier = Modifier.height(4.dp))
        SplitRadioButton(
            label = { Text("Second Button", maxLines = 3, overflow = TextOverflow.Ellipsis) },
            selected = selectedButton == 1,
            onSelectionClick = { selectedButton = 1 },
            selectionContentDescription = "Second",
            onContainerClick = {
                /* Do something */
            },
            containerClickLabel = "click",
            enabled = true,
        )
    }
}
by @alexstyl