Horizontal

fun Horizontal(selectedIndex: Int, modifier: Modifier = Modifier, role: Role = SegmentedControlDefaults.SemanticRole, enabled: Boolean = true, indicatorContent: @Composable (selectedIndex: Int, enabled: Boolean) -> Unit = DefaultHorizontalIndicator, content: @Composable SegmentedControlScope.(SegmentedButtonItem) -> Unit)(source)

Single-row segmented control for 2–5 segments.

All segments share equal width. The animated pill indicator always uses SegmentedControlShape.Pill (fully rounded); the shape is not configurable on this variant because the outer container is also pill-shaped.

Parameters

selectedIndex

Zero-based index of the currently selected segment. Must be in 0 until segmentCount; throws IllegalArgumentException otherwise.

role

The Role used for the segments. Defaults to Role.RadioButton to represent single selection but if you use the SegmentedControl to completely change the layout use bellow it then use Role.Tab

modifier

Modifier applied to the outermost Column that wraps the optional header and the control track.

enabled

When false all segments ignore input and their ripple is suppressed.

indicatorContent

Composable that draws the selection indicator. Receives the current selectedIndex so callers can vary the appearance per selection — useful for value scales such as energy ratings. Defaults to SegmentedControlDefaults.Indicator.

content

Segment declarations using SegmentedControlScope. Every call to a scope function adds one segment; call them in display order. Requires 2–5 calls.