We just launched Compose Examples featuring over 150+ components! Check it out →

Button

Android

Component in Wear Material Compose

Wear Material [Button] that offers a single slot to take any content (text, icon or image).

The [Button] is circular in shape. The recommended [Button] sizes can be obtained from [ButtonDefaults] - see [ButtonDefaults.DefaultButtonSize], [ButtonDefaults.LargeButtonSize], [ButtonDefaults.SmallButtonSize]. Icon content should be of size [ButtonDefaults.DefaultIconSize], [ButtonDefaults.LargeIconSize] or [ButtonDefaults.SmallIconSize] respectively.

The recommended set of [ButtonColors] styles can be obtained from [ButtonDefaults], e.g. [ButtonDefaults.primaryButtonColors] to get a color scheme for a primary [Button] which by default will have a solid background of [Colors.primary] and content color of [Colors.onPrimary].

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

Last updated:

Installation

dependencies {
   implementation("androidx.wear.compose:compose-material:1.5.0-alpha04")
}

Overloads

@Deprecated(
    "This overload is provided for backwards compatibility with Compose for Wear OS 1.0." +
        "A newer overload is available with an additional shape parameter.",
    level = DeprecationLevel.HIDDEN
)
@Composable
fun Button(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: ButtonColors = ButtonDefaults.primaryButtonColors(),
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    content: @Composable BoxScope.() -> 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.
colors[ButtonColors] that will be used to resolve the background and content color for this button in different states. See [ButtonDefaults.buttonColors].
interactionSourceThe [MutableInteractionSource] representing the stream of [Interaction]s for this Button. You can create and pass in your own remembered [MutableInteractionSource] if you want to observe [Interaction]s and customize the appearance / behavior of this Button in different [Interaction]s.
contentThe content displayed on the [Button] such as text, icon or image.
@Composable
fun Button(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: ButtonColors = ButtonDefaults.primaryButtonColors(),
    interactionSource: MutableInteractionSource? = null,
    shape: Shape = CircleShape,
    border: ButtonBorder = ButtonDefaults.buttonBorder(),
    content: @Composable BoxScope.() -> 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.
colors[ButtonColors] that will be used to resolve the background and content color for this button in different states. See [ButtonDefaults.buttonColors].
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.
shapeDefines the button's shape. It is strongly recommended to use the default as this shape is a key characteristic of the Wear Material Theme.
border[ButtonBorder] that will be used to resolve the button border in different states. See [ButtonDefaults.buttonBorder].
contentThe content displayed on the [Button] such as text, icon or image.

Code Examples

ButtonWithIcon

@Composable
fun ButtonWithIcon() {
    Button(
        onClick = { /* Do something */ },
        enabled = true,
    ) {
        Icon(
            painter = painterResource(id = R.drawable.ic_airplanemode_active_24px),
            contentDescription = "airplane",
            modifier =
                Modifier.size(ButtonDefaults.DefaultIconSize)
                    .wrapContentSize(align = Alignment.Center),
        )
    }
}

LargeButtonWithIcon

@Composable
fun LargeButtonWithIcon() {
    Button(
        onClick = { /* Do something */ },
        enabled = true,
        modifier = Modifier.size(ButtonDefaults.LargeButtonSize)
    ) {
        Icon(
            painter = painterResource(id = R.drawable.ic_airplanemode_active_24px),
            contentDescription = "airplane",
            modifier =
                Modifier.size(ButtonDefaults.LargeIconSize)
                    .wrapContentSize(align = Alignment.Center),
        )
    }
}

ButtonWithText

@Composable
fun ButtonWithText() {
    Button(
        onClick = { /* Do something */ },
        enabled = true,
        modifier = Modifier.size(ButtonDefaults.LargeButtonSize)
    ) {
        Text("Big")
    }
}
by @alexstyl