Radio Button

Radio Button

A selectable button that allows choosing one option from a set.


Installation

./gradlew lumo --add RadioButton

Usage

Basic Radio Button

var selectedOption by remember { mutableStateOf("option1") }
 
RadioButton(
    selected = selectedOption == "option1",
    onClick = { selectedOption = "option1" }
)

Radio Button with Label

RadioButton(
    selected = selected,
    onClick = { onOptionSelected() },
    content = {
        Text(
            text = "Option Label",
            modifier = Modifier.padding(start = 8.dp)
        )
    }
)

Radio Group

val options = listOf("Option 1", "Option 2", "Option 3")
var selectedOption by remember { mutableStateOf(options[0]) }
 
Column {
    options.forEach { option ->
        Row(
            modifier = Modifier.padding(vertical = 4.dp),
            verticalAlignment = Alignment.CenterVertically
        ) {
            RadioButton(
                selected = selectedOption == option,
                onClick = { selectedOption = option },
                content = {
                    Text(
                        text = option,
                        modifier = Modifier.padding(start = 8.dp)
                    )
                }
            )
        }
    }
}

API Documentation

Parameters

ParameterTypeDescription
modifierModifierModifier for the radio button
selectedBooleanWhether the radio button is selected
onClick(() -> Unit)?Callback when button is clicked
enabledBooleanWhether the button is enabled
colorsRadioButtonColorsColors for different states
interactionSourceMutableInteractionSourceSource of interactions for the button
content@Composable (() -> Unit)?Optional content