State of Compose 2023 results are in! Click here to learn more

← Back to Wear Material

CompactButton

Component
in
Wear Material
. Since 1.0.0

Overview

Code Examples

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

The CompactButton is circular in shape and has background size ButtonDefaults.ExtraSmallButtonSize. There is an optional transparent padding around the background, defaulted to ButtonDefaults.CompactButtonBackgroundPadding, which increases the clickable area. Icon content should have size ButtonDefaults.SmallIconSize.

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.

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

Overloads

CompactButton

@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
public fun CompactButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: ButtonColors = ButtonDefaults.primaryButtonColors(),
    backgroundPadding: Dp = ButtonDefaults.CompactButtonBackgroundPadding,
    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.
colorsButtonColors that will be used to resolve the background and content color for this button in different states. See ButtonDefaults.buttonColors.
backgroundPaddingIncreases the transparent clickable area around the background, defaults to ButtonDefaults.CompactButtonBackgroundPadding
interactionSourceThe MutableInteractionSource representing the stream of Interactions for this Button. You can create and pass in your own remembered MutableInteractionSource if you want to observe Interactions and customize the appearance / behavior of this Button in different Interactions.
contentThe content displayed on the CompactButton such as text, icon or image

CompactButton

@Composable
public fun CompactButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: ButtonColors = ButtonDefaults.primaryButtonColors(),
    backgroundPadding: Dp = ButtonDefaults.CompactButtonBackgroundPadding,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    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.
colorsButtonColors that will be used to resolve the background and content color for this button in different states. See ButtonDefaults.buttonColors.
backgroundPaddingIncreases the transparent clickable area around the background, defaults to ButtonDefaults.CompactButtonBackgroundPadding
interactionSourceThe MutableInteractionSource representing the stream of Interactions for this Button. You can create and pass in your own remembered MutableInteractionSource if you want to observe Interactions and customize the appearance / behavior of this Button in different Interactions.
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.
borderButtonBorder that will be used to resolve the button border in different states. See ButtonDefaults.outlinedButtonBorder.
contentThe content displayed on the CompactButton such as text, icon or image