Compose Modifier

selectable

Configure component to be selectable, usually as a part of a mutually exclusive group, where only one item can be selected at any point in time.

SelectableSample

@Sampled
@Composable
fun SelectableSample() {
    val option1 = Color.Red
    val option2 = Color.Blue
    var selectedOption by remember { mutableStateOf(option1) }
    Column {
        Text("Selected: $selectedOption")
        Row {
            listOf(option1, option2).forEach { color ->
                val selected = selectedOption == color
                Box(
                    Modifier.size(100.dp)
                        .background(color = color)
                        .selectable(selected = selected, onClick = { selectedOption = color })
                )
            }
        }
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: