androidx.compose.material3

RadioButton

Composable function

A radio button selects one option from a set. Selecting one deselects the others. Use radio buttons when the user should see all options at once. For many options, use a menu instead.

A radio button does not know about the others. You keep the selected option in a variable.

A group of options
A group of options
val options = listOf("Small", "Medium", "Large")
var selected by remember { mutableStateOf("Medium") }
Column(Modifier.selectableGroup()) {
    options.forEach { option ->
        Row(
            modifier = Modifier
                .width(200.dp)
                .selectable(selected = option == selected, onClick = { selected = option }, role = Role.RadioButton),
            verticalAlignment = Alignment.CenterVertically,
        ) {
            // The Row handles clicks, so the radio button itself does not.
            RadioButton(selected = option == selected, onClick = null)
            Text(option, Modifier.padding(start = 8.dp))
        }
    }
}
Selected, not selected and disabled
Selected, not selected and disabled
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
    RadioButton(selected = true, onClick = {})
    RadioButton(selected = false, onClick = {})
    RadioButton(selected = true, onClick = {}, enabled = false)
    RadioButton(selected = false, onClick = {}, enabled = false)
}

Parameters

@Composable
fun RadioButton(
    selected: Boolean,
    onClick: (() -> Unit)?,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: RadioButtonColors = RadioButtonDefaults.colors(),
    interactionSource: MutableInteractionSource? = null,
)

selected: BooleanRequired

Whether this option is selected. Usually option == selectedOption.

onClick: (() -> Unit)?Required

Called when the user clicks. Set your state to this option here. Pass null if a whole row handles the click. This makes the label clickable too, as in the first example. Also add Modifier.selectableGroup() to the parent, so screen readers treat the options as one group.

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position of the radio button. See the Modifier guide.

enabled: BooleanOptional

Default: true

Set to false to make the radio button gray and not clickable.

colors: RadioButtonColorsOptional

Default: RadioButtonDefaults.colors()

Sets the colors for selected, unselected and disabled. Make one with RadioButtonDefaults.colors.

Tertiary color when selected
Tertiary color when selected
RadioButton(
    selected = true,
    onClick = {},
    colors = RadioButtonDefaults.colors(selectedColor = MaterialTheme.colorScheme.tertiary),
)

interactionSource: MutableInteractionSource?Optional

Default: null

Lets you observe or control press, hover and focus states. Leave it null unless your code must react to them. See InteractionSource.

See also