New Compose Multiplatform components arrived on Composables UICheck it out →

Component in Wear Material 3 Compose

Button

Android

Base level Wear Material3 [Button] that offers a single slot to take any content. Used as the container for more opinionated [Button] components that take specific content such as icons and labels.

The [Button] is stadium-shaped by default and its standard height is designed to take 2 lines of text of [Typography.labelMedium] style. With localisation and/or large font sizes, the text can extend to a maximum of 3 lines in which case, the [Button] height adjusts to accommodate the contents.

[Button] takes the [ButtonDefaults.buttonColors] color scheme by default, with colored background, contrasting content color and no border. This is a high-emphasis button for the primary, most important or most common action on a screen.

Other recommended buttons with [ButtonColors] for different levels of emphasis are: [FilledTonalButton] which defaults to [ButtonDefaults.filledTonalButtonColors], [OutlinedButton] which defaults to [ButtonDefaults.outlinedButtonColors] and [ChildButton] which defaults to [ButtonDefaults.childButtonColors]. Buttons can also take an image background using [ButtonDefaults.imageBackgroundButtonColors].

Button can be enabled or disabled. A disabled button will not respond to click events.

Last updated:

Installation

dependencies {
   implementation("androidx.wear.compose:compose-material3:1.0.0-alpha23")
}

Overloads

@Composable
fun Button(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    shape: Shape = FilledButtonTokens.ContainerShape.value,
    colors: ButtonColors = ButtonDefaults.buttonColors(),
    border: BorderStroke? = null,
    contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
    interactionSource: MutableInteractionSource? = null,
    content: @Composable RowScope.() -> Unit,
)

Parameters

namedescription
onClickWill be called when the user clicks the button
modifierModifier to be applied to the button
enabledControls the enabled state of the button. When false, this button will not be clickable
shapeDefines the button's shape. It is strongly recommended to use the default as this shape is a key characteristic of the Wear Material3 Theme
colors[ButtonColors] that will be used to resolve the background and content color for this button in different states. See [ButtonDefaults.buttonColors].
borderOptional [BorderStroke] that will be used to resolve the border for this button in different states.
contentPaddingThe spacing values to apply internally between the container and the content
interactionSourcean optional hoisted [MutableInteractionSource] for observing and emitting [Interaction]s 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.
contentSlot for composable body content displayed on the Button
@Composable
fun Button(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    secondaryLabel: (@Composable RowScope.() -> Unit)? = null,
    icon: (@Composable BoxScope.() -> Unit)? = null,
    enabled: Boolean = true,
    shape: Shape = FilledButtonTokens.ContainerShape.value,
    colors: ButtonColors = ButtonDefaults.buttonColors(),
    border: BorderStroke? = null,
    contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
    interactionSource: MutableInteractionSource? = null,
    label: @Composable RowScope.() -> Unit,
)

Parameters

namedescription
onClickWill be called when the user clicks the button
modifierModifier to be applied to the button
secondaryLabelA slot for providing the button's secondary label. The contents are expected to be text which is "start" aligned if there is an icon preset and "start" or "center" aligned if not. label and secondaryLabel contents should be consistently aligned.
iconA slot for providing the button's icon. The contents are expected to be a horizontally and vertically aligned icon of size [ButtonDefaults.IconSize] or [ButtonDefaults.LargeIconSize].
enabledControls the enabled state of the button. When false, this button will not be clickable
shapeDefines the button's shape. It is strongly recommended to use the default as this shape is a key characteristic of the Wear Material3 Theme
colors[ButtonColors] that will be used to resolve the background and content color for this button in different states. See [ButtonDefaults.buttonColors]. Defaults to [ButtonDefaults.buttonColors]
borderOptional [BorderStroke] that will be used to resolve the button border in different states.
contentPaddingThe spacing values to apply internally between the container and the content
interactionSourcean optional hoisted [MutableInteractionSource] for observing and emitting [Interaction]s 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.
labelA slot for providing the button's main label. The contents are expected to be text which is "start" aligned if there is an icon preset and "start" or "center" aligned if not.

Code Examples

SimpleButtonSample

@Composable
@Sampled
fun SimpleButtonSample() {
    Button(
        onClick = { /* Do something */ },
        label = { Text("Button") }
    )
}

ButtonSample

@Composable
@Sampled
fun ButtonSample() {
    Button(
        onClick = { /* Do something */ },
        label = { Text("Button") },
        secondaryLabel = { Text("Secondary label") },
        icon = {
            Icon(
                Icons.Filled.Favorite,
                contentDescription = "Favorite icon",
                modifier = Modifier.size(ButtonDefaults.IconSize)
            )
        }
    )
}