{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

MultiChoiceSegmentedButtonRowScope

@ExperimentalMaterial3Api
public interface MultiChoiceSegmentedButtonRowScope extends RowScope


Scope for the children of a MultiChoiceSegmentedButtonRow

Summary

Extension functions

default final void
@Composable
@ExperimentalMaterial3Api
SegmentedButtonKt.SegmentedButton(
    @NonNull MultiChoiceSegmentedButtonRowScope receiver,
    boolean checked,
    @NonNull Function1<@NonNull BooleanUnit> onCheckedChange,
    @NonNull Shape shape,
    @NonNull Modifier modifier,
    boolean enabled,
    @NonNull SegmentedButtonColors colors,
    @NonNull BorderStroke border,
    @NonNull MutableInteractionSource interactionSource,
    @Composable @NonNull Function0<Unit> icon,
    @Composable @NonNull Function0<Unit> label
)

Material Segmented Button.

Inherited methods

From androidx.compose.foundation.layout.RowScope
abstract @NonNull Modifier
orgKt.align(
    @NonNull Modifier receiver,
    @NonNull Alignment.Vertical alignment
)

Align the element vertically within the Row.

abstract @NonNull Modifier
orgKt.alignBy(
    @NonNull Modifier receiver,
    @NonNull Function1<@NonNull Measured, @NonNull Integer> alignmentLineBlock
)

Position the element vertically such that the alignment line for the content as determined by alignmentLineBlock aligns with sibling elements also configured to alignBy.

abstract @NonNull Modifier
orgKt.alignBy(
    @NonNull Modifier receiver,
    @NonNull HorizontalAlignmentLine alignmentLine
)

Position the element vertically such that its alignmentLine aligns with sibling elements also configured to alignBy.

abstract @NonNull Modifier

Position the element vertically such that its first baseline aligns with sibling elements also configured to alignByBaseline or alignBy.

abstract @NonNull Modifier
orgKt.weight(@NonNull Modifier receiver, float weight, boolean fill)

Size the element's width proportional to its weight relative to other weighted sibling elements in the Row.

Extension functions

SegmentedButtonKt.SegmentedButton

@Composable
@ExperimentalMaterial3Api
default final void SegmentedButtonKt.SegmentedButton(
    @NonNull MultiChoiceSegmentedButtonRowScope receiver,
    boolean checked,
    @NonNull Function1<@NonNull BooleanUnit> onCheckedChange,
    @NonNull Shape shape,
    @NonNull Modifier modifier,
    boolean enabled,
    @NonNull SegmentedButtonColors colors,
    @NonNull BorderStroke border,
    @NonNull MutableInteractionSource interactionSource,
    @Composable @NonNull Function0<Unit> icon,
    @Composable @NonNull Function0<Unit> label
)

Material Segmented Button. Segmented buttons help people select options, switch views, or sort elements.

A default Toggleable Segmented Button. Also known as Outlined Segmented Button. See Modifier.toggleable.

Toggleable segmented buttons should be used for cases where the selection is not mutually exclusive.

This should typically be used inside of a MultiChoiceSegmentedButtonRow

For a sample showing Segmented button with only checked icons see:

import androidx.compose.foundation.layout.size
import androidx.compose.material.Icon
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.TrendingUp
import androidx.compose.material.icons.filled.BookmarkBorder
import androidx.compose.material.icons.filled.StarBorder
import androidx.compose.material3.MultiChoiceSegmentedButtonRow
import androidx.compose.material3.SegmentedButton
import androidx.compose.material3.SegmentedButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier

val checkedList = remember { mutableStateListOf<Int>() }
val options = listOf("Favorites", "Trending", "Saved")
val icons = listOf(
    Icons.Filled.StarBorder,
    Icons.AutoMirrored.Filled.TrendingUp,
    Icons.Filled.BookmarkBorder
)
MultiChoiceSegmentedButtonRow {
    options.forEachIndexed { index, label ->
        SegmentedButton(
            shape = SegmentedButtonDefaults.itemShape(index = index, count = options.size),
            icon = {
                SegmentedButtonDefaults.Icon(active = index in checkedList) {
                    Icon(
                        imageVector = icons[index],
                        contentDescription = null,
                        modifier = Modifier.size(SegmentedButtonDefaults.IconSize)
                    )
                }
            },
            onCheckedChange = {
                if (index in checkedList) {
                    checkedList.remove(index)
                } else {
                    checkedList.add(index)
                }
            },
            checked = index in checkedList
        ) {
            Text(label)
        }
    }
}
Parameters
boolean checked

whether this button is checked or not

@NonNull Function1<@NonNull BooleanUnit> onCheckedChange

callback to be invoked when the button is clicked. therefore the change of checked state in requested.

@NonNull Shape shape

the shape for this button

@NonNull Modifier modifier

the Modifier to be applied to this button

boolean enabled

controls the enabled state of this button. When false, this component will not respond to user input, and it will appear visually disabled and disabled to accessibility services.

@NonNull SegmentedButtonColors colors

SegmentedButtonColors that will be used to resolve the colors used for this

@NonNull BorderStroke border

the border for this button, see SegmentedButtonColors Button in different states

@NonNull MutableInteractionSource interactionSource

the MutableInteractionSource representing the stream of Interactions for this button. You can create and pass in your own remembered instance to observe Interactions and customize the appearance / behavior of this button in different states.

@Composable @NonNull Function0<Unit> icon

the icon slot for this button, you can pass null in unchecked, in which case the content will displace to show the checked icon, or pass different icon lambdas for unchecked and checked in which case the icons will crossfade.

@Composable @NonNull Function0<Unit> label

content to be rendered inside this button