State of Compose 2023 results are in! Click here to learn more

← Back to Material Compose

RadioGroup

Component
in
Material
. Since 0.1.0-dev15

Overview

Code Examples

Components for creating mutually exclusive set of RadioButtons. Because of the nature of mutually exclusive set, when radio button is selected, it can't be unselected by being pressed again.

If you want a simplified version with Column of RadioGroupScope.RadioGroupTextItem, consider using version that accepts list of String options and doesn't require any children

@deprecated RadioGroup provides no layout and no additional logic. It is recommended to create such groups manually, to gain flexibility and full control over the state and the appearance

See example of a simple radio group-like layout

Overloads

RadioGroup

@Composable
@Suppress("DEPRECATION")
fun RadioGroup(content: @Composable RadioGroupScope.() -> Unit)

RadioGroup

@Deprecated(
    "RadioGroup provides hardcoded layout and no flexibility. It is recommended to create such " +
            "layouts manually, to gain flexibility and full control over the state and the " +
            "appearance",
    replaceWith = ReplaceWith(
        "Column(modifier) {\n" +
                "options.forEach { text ->\n" +
                "Row(Modifier\n" +
                ".fillMaxWidth()\n" +
                ".selectable(\n" +
                "selected = (text == selectedOption),\n" +
                "onClick = { onSelectedChange(text) }\n" +
                ")\n" +
                ".padding(horizontal = 16.dp)\n" +
                ") {\n" +
                "RadioButton(\n" +
                "selected = (text == selectedOption),\n" +
                "onClick = { onSelectedChange(text) },\n" +
                "selectedColor = radioColor\n" +
                ")\n" +
                "Text(\n" +
                "text = text,\n" +
                "style = MaterialTheme.typography.body1.merge(textStyle),\n" +
                "modifier = Modifier.padding(start = 16.dp)\n" +
                ")\n" +
                "}\n" +
                "}" +
                "}",
        "androidx.compose.material.RadioButton",
        "androidx.compose.foundation.Text",
        "androidx.compose.foundation.layout.Row",
        "androidx.compose.foundation.layout.Column",
        "androidx.compose.foundation.layout.fillMaxWidth",
        "androidx.compose.ui.Modifier",
        "androidx.compose.ui.unit.dp",
        "androidx.compose.foundation.selection.selectable"
    )
)
@Composable
fun RadioGroup(
    options: List<String>,
    selectedOption: String?,
    onSelectedChange: (String) -> Unit,
    modifier: Modifier = Modifier,
    radioColor: Color = MaterialTheme.colors.secondary,
    textStyle: TextStyle? = null
)

Parameters

NameDescription
optionslist of String to provide RadioButtons label
selectedOptionlabel which represents selected RadioButton, or null if nothing is selected
onSelectedChangecallback to be invoked when RadioButton is clicked, therefore the selection of this item is requested
modifierModifier to be applied to the radio group layout
radioColorcolor for RadioButtons when selected.
textStyleparameters for text customization @deprecated RadioGroup provides hardcoded layout and no flexibility. It is recommended to create such layouts manually, to gain flexibility and full control over the state and the appearance. See example of a simple radio group-like layout @sample androidx.compose.material.samples.RadioGroupSampl