androidx.compose.material3

SingleChoiceSegmentedButtonRow

Composable function

A segmented button is a row of joined buttons. Use it to switch views or pick options, with two to five choices.

Inside the row, add one SegmentedButton per option. SegmentedButton only exists inside a row.

Pick one option
Pick one option
val options = listOf("Day", "Week", "Month")
var selected by remember { mutableIntStateOf(1) }
SingleChoiceSegmentedButtonRow {
    options.forEachIndexed { index, label ->
        SegmentedButton(
            selected = index == selected,
            onClick = { selected = index },
            shape = SegmentedButtonDefaults.itemShape(index = index, count = options.size),
        ) { Text(label) }
    }
}
Pick several options
Pick several options
val options = listOf("Walk", "Bike", "Car")
val checked = remember { mutableStateListOf(true, false, true) }
MultiChoiceSegmentedButtonRow {
    options.forEachIndexed { index, label ->
        SegmentedButton(
            checked = checked[index],
            onCheckedChange = { checked[index] = it },
            shape = SegmentedButtonDefaults.itemShape(index = index, count = options.size),
        ) { Text(label) }
    }
}

Parameters

@Composable
fun SingleChoiceSegmentedButtonRow(
    modifier: Modifier = Modifier,
    space: Dp = SegmentedButtonDefaults.BorderWidth,
    content: @Composable SingleChoiceSegmentedButtonRowScope.() -> Unit,
)

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position. See the Modifier guide.

space: DpOptional

Default: SegmentedButtonDefaults.BorderWidth

The overlap between buttons, so their borders join. Default: one border width.

content: @Composable SingleChoiceSegmentedButtonRowScope.() -> UnitRequired

The buttons. Add one SegmentedButton per option.

Rows and buttons