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

← Back to Wear Material 3

ChildButton

Component
in
Wear Material 3
. Since 1.0.0-alpha03

Overview

Code Examples

Video

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

The ChildButton 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 ChildButton height adjusts to accommodate the contents. The ChildButton can have an icon or image horizontally parallel to the two lines of text.

ChildButton takes the ButtonDefaults.childButtonColors color scheme by default, with a transparent background and no border. This is a low-emphasis button for optional or supplementary actions with the least amount of prominence.

Other recommended buttons with ButtonColors for different levels of emphasis are: Button which defaults to ButtonDefaults.filledButtonColors, FilledTonalButton which defaults to ButtonDefaults.filledTonalButtonColors, OutlinedButton which defaults to ButtonDefaults.outlinedButtonColors and 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.

TODO(b/261838497) Add Material3 UX guidance links

Example of a ChildButton:

Overloads

ChildButton

@Composable
fun ChildButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    shape: Shape = ChildButtonTokens.ContainerShape.value,
    colors: ButtonColors = ButtonDefaults.childButtonColors(),
    border: BorderStroke? = null,
    contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    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
colorsButtonColors that will be used to resolve the background and content color for this button in different states. See ButtonDefaults.childButtonColors.
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
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

ChildButton

@Composable
fun ChildButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    secondaryLabel: (@Composable RowScope.() -> Unit)? = null,
    icon: (@Composable BoxScope.() -> Unit)? = null,
    enabled: Boolean = true,
    shape: Shape = ChildButtonTokens.ContainerShape.value,
    colors: ButtonColors = ButtonDefaults.childButtonColors(),
    border: BorderStroke? = null,
    contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    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. In order to correctly render when the Button is not enabled, the icon must set its alpha value to LocalContentAlpha.
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
colorsButtonColors that will be used to resolve the background and content color for this button in different states. See ButtonDefaults.childButtonColors.
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
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.
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