androidx.compose.material3

SegmentedListItemSince 1.11Experimental

Composable function

One of the list item types. It works like ListItem. Only the parameters that differ are described here.

Get the shape for each position with ListItemDefaults.segmentedShapes(index, count), and keep a small gap between the items.

Segmented items: only the outer corners are roundExpressive theme
Segmented items: only the outer corners are round
val items = listOf("Wi-Fi", "Bluetooth", "Mobile data")
Column(Modifier.width(360.dp), verticalArrangement = Arrangement.spacedBy(ListItemDefaults.SegmentedGap)) {
    items.forEachIndexed { index, label ->
        SegmentedListItem(
            onClick = {},
            shapes = ListItemDefaults.segmentedShapes(index = index, count = items.size),
            trailingContent = { Icon(Icons.AutoMirrored.Filled.KeyboardArrowRight, null) },
        ) { Text(label) }
    }
}

BasicExperimental

Not clickable. Add Modifier.clickable yourself if needed.

@Composable
fun SegmentedListItem(
    onClick: () -> Unit,
    shapes: ListItemShapes,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    leadingContent: @Composable (() -> Unit)? = null,
    trailingContent: @Composable (() -> Unit)? = null,
    overlineContent: @Composable (() -> Unit)? = null,
    supportingContent: @Composable (() -> Unit)? = null,
    verticalAlignment: Alignment.Vertical = ListItemDefaults.verticalAlignment(),
    onLongClick: (() -> Unit)? = null,
    onLongClickLabel: String? = null,
    colors: ListItemColors = ListItemDefaults.segmentedColors(),
    elevation: ListItemElevation = ListItemDefaults.elevation(),
    contentPadding: PaddingValues = ListItemDefaults.ContentPadding,
    interactionSource: MutableInteractionSource? = null,
    content: @Composable () -> Unit,
)

Defaults that differ from ListItem:

Same as in ListItem: onClick, shapes, modifier, enabled, leadingContent, trailingContent, overlineContent, supportingContent, verticalAlignment, onLongClick, onLongClickLabel, colors, elevation, contentPadding, interactionSource, content.

ClickableExperimental

Takes onClick. The headline goes in content.

@Composable
fun SegmentedListItem(
    selected: Boolean,
    onClick: () -> Unit,
    shapes: ListItemShapes,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    leadingContent: @Composable (() -> Unit)? = null,
    trailingContent: @Composable (() -> Unit)? = null,
    overlineContent: @Composable (() -> Unit)? = null,
    supportingContent: @Composable (() -> Unit)? = null,
    verticalAlignment: Alignment.Vertical = ListItemDefaults.verticalAlignment(),
    onLongClick: (() -> Unit)? = null,
    onLongClickLabel: String? = null,
    colors: ListItemColors = ListItemDefaults.segmentedColors(),
    elevation: ListItemElevation = ListItemDefaults.elevation(),
    contentPadding: PaddingValues = ListItemDefaults.ContentPadding,
    interactionSource: MutableInteractionSource? = null,
    content: @Composable () -> Unit,
)

Defaults that differ from ListItem:

Same as in ListItem: selected, onClick, shapes, modifier, enabled, leadingContent, trailingContent, overlineContent, supportingContent, verticalAlignment, onLongClick, onLongClickLabel, colors, elevation, contentPadding, interactionSource, content.

SelectableExperimental

Takes selected and onClick.

@Composable
fun SegmentedListItem(
    checked: Boolean,
    onCheckedChange: (Boolean) -> Unit,
    shapes: ListItemShapes,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    leadingContent: @Composable (() -> Unit)? = null,
    trailingContent: @Composable (() -> Unit)? = null,
    overlineContent: @Composable (() -> Unit)? = null,
    supportingContent: @Composable (() -> Unit)? = null,
    verticalAlignment: Alignment.Vertical = ListItemDefaults.verticalAlignment(),
    onLongClick: (() -> Unit)? = null,
    onLongClickLabel: String? = null,
    colors: ListItemColors = ListItemDefaults.segmentedColors(),
    elevation: ListItemElevation = ListItemDefaults.elevation(),
    contentPadding: PaddingValues = ListItemDefaults.ContentPadding,
    interactionSource: MutableInteractionSource? = null,
    content: @Composable () -> Unit,
)

Defaults that differ from ListItem:

Same as in ListItem: checked, onCheckedChange, shapes, modifier, enabled, leadingContent, trailingContent, overlineContent, supportingContent, verticalAlignment, onLongClick, onLongClickLabel, colors, elevation, contentPadding, interactionSource, content.

List item types

See also