New Compose Multiplatform components arrived on Composables UICheck it out →

RadioButton

The Wear Material [RadioButton] offers four slots and a specific layout for an icon, a label, a secondaryLabel and selection control (such as [Radio]). The icon and secondaryLabel are optional. The items are laid out in a row with the optional icon at the start, a column containing the two label slots in the middle and a slot for the selection control at the end.

The [RadioButton] 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 [RadioButton] height adjusts to accommodate the contents. The label and secondary label should be start aligned.

Note that Modifier.selectableGroup() must be present on the parent control (such as Column) to ensure correct accessibility behavior.

Last updated:

Installation

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

Overloads

@Composable
fun RadioButton(
    selected: Boolean,
    onSelect: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    selectionControl: @Composable SelectionControlScope.() -> Unit = {
        Radio()
    },
    shape: Shape = RadioButtonTokens.Shape.value,
    colors: RadioButtonColors = RadioButtonDefaults.radioButtonColors(),
    contentPadding: PaddingValues = RadioButtonDefaults.ContentPadding,
    interactionSource: MutableInteractionSource? = null,
    icon: @Composable (BoxScope.() -> Unit)? = null,
    secondaryLabel: @Composable (RowScope.() -> Unit)? = null,
    label: @Composable RowScope.() -> Unit
)

Parameters

namedescription
selectedBoolean flag indicating whether this button is currently selected.
onSelectCallback to be invoked when this button has been selected by clicking.
selectionControlA slot for the button's selection control. The [Radio] selection control is provided for this purpose.
modifierModifier to be applied to the [RadioButton].
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[RadioButtonColors] 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.
interactionSourcean optional hoisted [MutableInteractionSource] for observing and emitting [Interaction]s for this radio button. You can use this to change the radio button's appearance or preview the radio button in different states. Note that if null is provided, interactions will still happen internally.
iconAn optional slot for providing an icon to indicate the purpose of the button. The contents are expected to be center-aligned, both horizontally and vertically, and should be an icon of size 24.dp.
secondaryLabelA slot for providing the button's secondary label. The contents are expected to be text which is "start" aligned.
labelA slot for providing the button's main label. The contents are expected to be text which is "start" aligned.

Code Example

RadioButton

@Composable
@Sampled
fun RadioButton() {
    Column(modifier = Modifier.selectableGroup()) {
        var selectedButton by remember { mutableStateOf(0) }
        // RadioButton uses the Radio selection control by default.
        RadioButton(
            label = {
                Text("Radio button", maxLines = 3, overflow = TextOverflow.Ellipsis)
            },
            secondaryLabel = {
                Text("With secondary label", maxLines = 2, overflow = TextOverflow.Ellipsis)
            },
            selected = selectedButton == 0,
            onSelect = { selectedButton = 0 },
            icon = {
                Icon(
                    Icons.Filled.Favorite,
                    contentDescription = "Favorite icon"
                )
            },
            enabled = true,
        )
        Spacer(modifier = Modifier.height(4.dp))
        RadioButton(
            label = {
                Text("Radio button", maxLines = 3, overflow = TextOverflow.Ellipsis)
            },
            secondaryLabel = {
                Text("With secondary label", maxLines = 3, overflow = TextOverflow.Ellipsis)
            },
            selected = selectedButton == 1,
            onSelect = { selectedButton = 1 },
            icon = {
                Icon(
                    Icons.Filled.Favorite,
                    contentDescription = "Favorite icon"
                )
            },
            enabled = true,
        )
    }
}