1.4 KiB
1.4 KiB
RadioButton
Radio buttons allow users to select one option from a set.
Example
@Composable
fun RadioButtonSample() {
val radioOptions = listOf("A", "B", "C")
val (selectedOption, onOptionSelected) = remember { mutableStateOf(radioOptions[1] ) }
Column {
radioOptions.forEach { text ->
Row(
Modifier
.fillMaxWidth()
.selectable(
selected = (text == selectedOption),
onClick = {
onOptionSelected(text)
}
)
.padding(horizontal = 16.dp)
) {
RadioButton(
selected = (text == selectedOption),
onClick = { onOptionSelected(text) }
)
Text(
text = text,
style = MaterialTheme.typography.body1.merge(),
modifier = Modifier.padding(start = 16.dp)
)
}
}
}
}
See also:
- Official Docs
- [Full Example Code]({{ site.samplefolder }}/material/radiobutton/RadioButtonSample.kt)
