ButtonKt

Added in 1.0.0-alpha01

public final class ButtonKt


Summary

Public methods

static final void
@Composable
Button(
    @NonNull Function0<Unit> onClick,
    @NonNull Modifier modifier,
    boolean enabled,
    @NonNull ButtonSize buttonSize,
    @Composable Function0<Unit> leadingIcon,
    @Composable Function0<Unit> trailingIcon,
    @NonNull Shape shape,
    @NonNull Color color,
    @NonNull Color contentColor,
    BorderStroke border,
    @NonNull PaddingValues contentPadding,
    MutableInteractionSource interactionSource,
    @Composable @NonNull Function1<@NonNull RowScopeUnit> content
)

Button is a component used for exposing actions to a user.

Public methods

@Composable
public static final void Button(
    @NonNull Function0<Unit> onClick,
    @NonNull Modifier modifier,
    boolean enabled,
    @NonNull ButtonSize buttonSize,
    @Composable Function0<Unit> leadingIcon,
    @Composable Function0<Unit> trailingIcon,
    @NonNull Shape shape,
    @NonNull Color color,
    @NonNull Color contentColor,
    BorderStroke border,
    @NonNull PaddingValues contentPadding,
    MutableInteractionSource interactionSource,
    @Composable @NonNull Function1<@NonNull RowScopeUnit> content
)

Button is a component used for exposing actions to a user.

import androidx.xr.glimmer.Button
import androidx.xr.glimmer.Text

Button(onClick = {}) { Text("Send") }

Buttons can use icons to provide more context about the action:

import androidx.xr.glimmer.Button
import androidx.xr.glimmer.Icon
import androidx.xr.glimmer.Text

Button(onClick = {}, leadingIcon = { Icon(FavoriteIcon, "Localized description") }) {
    Text("Send")
}

There are multiple button size variants - providing a different ButtonSize will affect default values used inside this button, such as the minimum height and the size of icons inside this button. Note that you can still provide a size modifier such as androidx.compose.foundation.layout.size to change the layout size of this button, buttonSize affects default values and values internal to the button.

import androidx.xr.glimmer.Button
import androidx.xr.glimmer.ButtonSize
import androidx.xr.glimmer.Text

Button(onClick = {}, buttonSize = ButtonSize.Large) { Text("Send") }
Parameters
@NonNull Function0<Unit> onClick

called when this button is clicked

@NonNull Modifier modifier

the Modifier to be applied to this button

boolean enabled

controls the enabled state of this button. When false, this button will not respond to user input

@NonNull ButtonSize buttonSize

the size variant of this button, represented as a ButtonSize. Changing buttonSize will affect some default values used by this button - but the final resulting size of the button will still be calculated based on the content of the button, and any provided size modifiers such as androidx.compose.foundation.layout.size. For example, setting a 100.dp size using a size modifier will result in the same layout size regardless of buttonSize, but the provided buttonSize will affect other properties such as padding values and the size of icons.

@Composable Function0<Unit> leadingIcon

optional leading icon to be placed before the content. This is typically an Icon.

@Composable Function0<Unit> trailingIcon

optional trailing icon to be placed after the content. This is typically an Icon.

@NonNull Shape shape

the Shape used to clip this button, and also used to draw the background and border

@NonNull Color color

background color of this button

@NonNull Color contentColor

content color used by components inside content

BorderStroke border

the border to draw around this button

@NonNull PaddingValues contentPadding

the spacing values to apply internally between the container and the content

MutableInteractionSource interactionSource

an optional hoisted MutableInteractionSource for observing and emitting Interactions for this button. You can use this to change the button's appearance or preview the button in different states. Note that if null is provided, interactions will still happen internally.

@Composable @NonNull Function1<@NonNull RowScopeUnit> content

the main content, typically Text, to display inside this button