ButtonGroupScope

Interface

Common
@ExperimentalMaterial3ExpressiveApi
interface ButtonGroupScope

Button group scope used to indicate a Modifier.weight and Modifier.animateWidth of a child element. Also defines the DSL to build the content of a ButtonGroup

Functions

fun Modifier.weight(
        @FloatRange(from = 0.0, fromInclusive = false) weight: Float,
        fill: Boolean = true,
    ): Modifier

Size the element's width proportional to its weight relative to other weighted sibling elements in the ButtonGroup. The parent will divide the horizontal space remaining after measuring unweighted child elements and distribute it according to this weight. When fill is true, the element will be forced to occupy the whole width allocated to it. Otherwise, the element is allowed to be smaller - this will result in ButtonGroup being smaller, as the unused allocated width will not be redistributed to other siblings.

Parameters

weightThe proportional width to give to this element, as related to the total of all weighted siblings. Must be positive.
fillWhen true, the element will occupy the whole width allocated.
fun Modifier.weight(@FloatRange(from = 0.0, fromInclusive = false) weight: Float): Modifier

Size the element's width proportional to its weight relative to other weighted sibling elements in the ButtonGroup. The parent will divide the horizontal space remaining after measuring unweighted child elements and distribute it according to this weight.

Parameters

weightThe proportional width to give to this element, as related to the total of all weighted siblings. Must be positive.
fun Modifier.animateWidth(interactionSource: InteractionSource): Modifier

Specifies the interaction source to use with this item. This is used to listen to events and animate growing the pressed button and shrink the neighbor(s).

Parameters

interactionSourcethe InteractionSource that button group will observe.
fun clickableItem(
        onClick: () -> Unit,
        label: String,
        icon: (@Composable () -> Unit)? = null,
        weight: Float = Float.NaN,
        enabled: Boolean = true,
    )

Adds a clickable item to the ButtonGroup.

Parameters

onClickThe action to perform when the item is clicked.
labelThe text label for the item.
iconAn optional composable representing the item's icon.
weightthe weight to be applied to this item, please see ButtonGroupScope.weight
enabledWhether the item is enabled.
fun toggleableItem(
        checked: Boolean,
        label: String,
        onCheckedChange: (Boolean) -> Unit,
        icon: (@Composable () -> Unit)? = null,
        weight: Float = Float.NaN,
        enabled: Boolean = true,
    )

Adds a toggleable item to the ButtonGroup.

Parameters

checkedWhether the item is currently checked.
onCheckedChangeThe action to perform when the item's checked state changes.
iconAn optional composable representing the item's icon.
enabledWhether the item is enabled.
weightthe weight to be applied to this item, please see ButtonGroupScope.weight
labelThe text label for the item.
fun customItem(
        buttonGroupContent: @Composable () -> Unit,
        menuContent: @Composable (ButtonGroupMenuState) -> Unit,
    )

Adds a custom item to the ButtonGroup.

Parameters

buttonGroupContentThe composable to display in the app bar.
menuContentThe composable to display in the overflow menu. It receives an ButtonGroupMenuState instance.