androidx.compose.material3

SegmentedButton

Composable function

A part of SingleChoiceSegmentedButtonRow. See that page for an overview and examples.

Checkable

For a multi-choice row. Takes checked and onCheckedChange.

@Composable
fun MultiChoiceSegmentedButtonRowScope.SegmentedButton(
    checked: Boolean,
    onCheckedChange: (Boolean) -> Unit,
    shape: Shape,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: SegmentedButtonColors = SegmentedButtonDefaults.colors(),
    border: BorderStroke = SegmentedButtonDefaults.borderStroke(colors.borderColor(enabled, checked)),
    contentPadding: PaddingValues = SegmentedButtonDefaults.ContentPadding,
    interactionSource: MutableInteractionSource? = null,
    icon: @Composable () -> Unit = { SegmentedButtonDefaults.Icon(checked) },
    label: @Composable () -> Unit,
)

checked: BooleanRequired

Whether this option is checked, in a multi-choice row.

onCheckedChange: (Boolean) -> UnitRequired

Called with the new value when the button is clicked.

shape: ShapeRequired

The outline of one button. Use SegmentedButtonDefaults.itemShape(index, count): it rounds only the outer corners of the first and last button.

enabled: BooleanOptional

Default: true

Set to false to make the button gray and not clickable.

colors: SegmentedButtonColorsOptional

Default: SegmentedButtonDefaults.colors()

Sets colors for selected, unselected and disabled. Make one with SegmentedButtonDefaults.colors.

border: BorderStrokeOptional

Default: SegmentedButtonDefaults.borderStroke(colors.borderColor(enabled, checked))

The outline of the button.

contentPadding: PaddingValuesOptionalSince 1.9

Default: SegmentedButtonDefaults.ContentPadding

Space between the edge of the button and its content.

interactionSource: MutableInteractionSource?Optional

Default: null

Lets you observe or control press, hover and focus states. Leave it null unless your code must react to them. See InteractionSource.

icon: @Composable () -> UnitOptional

Default: { SegmentedButtonDefaults.Icon(checked) }

The icon before the label. Default: a checkmark while selected.

label: @Composable () -> UnitRequired

The text of the button.

Same as in SingleChoiceSegmentedButtonRow: modifier.

Selectable

For a single-choice row. Takes selected and onClick.

@Composable
fun SingleChoiceSegmentedButtonRowScope.SegmentedButton(
    selected: Boolean,
    onClick: () -> Unit,
    shape: Shape,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: SegmentedButtonColors = SegmentedButtonDefaults.colors(),
    border: BorderStroke = SegmentedButtonDefaults.borderStroke(colors.borderColor(enabled, selected)),
    contentPadding: PaddingValues = SegmentedButtonDefaults.ContentPadding,
    interactionSource: MutableInteractionSource? = null,
    icon: @Composable () -> Unit = { SegmentedButtonDefaults.Icon(selected) },
    label: @Composable () -> Unit,
)

selected: BooleanRequired

Whether this option is selected, in a single-choice row.

onClick: () -> UnitRequired

Called when the button is clicked. Set your selected option here.

Same as above: shape, enabled, colors, border, contentPadding, interactionSource, icon, label.

Same as in SingleChoiceSegmentedButtonRow: modifier.

Rows and buttons