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

SingleChoiceSegmentedButtonRowScope

@ExperimentalMaterial3Api
public interface SingleChoiceSegmentedButtonRowScope extends RowScope


Scope for the children of a SingleChoiceSegmentedButtonRow

Summary

Extension functions

default final void
@Composable
@ExperimentalMaterial3Api
SegmentedButtonKt.SegmentedButton(
    @NonNull SingleChoiceSegmentedButtonRowScope receiver,
    boolean selected,
    @NonNull Function0<Unit> onClick,
    @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 SingleChoiceSegmentedButtonRowScope receiver,
    boolean selected,
    @NonNull Function0<Unit> onClick,
    @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.selectable.

Selectable segmented buttons should be used for cases where the selection is mutually exclusive, when only one button can be selected at a time.

This should typically be used inside of a SingleChoiceSegmentedButtonRow

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

import androidx.compose.foundation.layout.size
import androidx.compose.material3.SegmentedButton
import androidx.compose.material3.SegmentedButtonDefaults
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
import androidx.compose.material3.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember

var selectedIndex by remember { mutableStateOf(0) }
val options = listOf("Day", "Month", "Week")
SingleChoiceSegmentedButtonRow {
    options.forEachIndexed { index, label ->
        SegmentedButton(
            shape = SegmentedButtonDefaults.itemShape(index = index, count = options.size),
            onClick = { selectedIndex = index },
            selected = index == selectedIndex
        ) {
            Text(label)
        }
    }
}
Parameters
boolean selected

whether this button is selected or not

@NonNull Function0<Unit> onClick

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