ButtonKt
public final class ButtonKt
Summary
Public methods
avatarButton
public static final @NonNull LayoutElementBuilders.LayoutElement avatarButton(
@NonNull MaterialScope receiver,
@NonNull ModifiersBuilders.Clickable onClick,
@NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> labelContent,
@NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> avatarContent,
@NonNull LayoutModifier modifier,
Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> secondaryLabelContent,
@NonNull DimensionBuilders.ContainerDimension height,
@NonNull ModifiersBuilders.Corner shape,
@NonNull ButtonColors colors,
@NonNull AvatarButtonStyle style,
int horizontalAlignment,
@NonNull ModifiersBuilders.Padding contentPadding
)
Opinionated ProtoLayout Material3 pill shape avatar button that offers up to three slots to take content representing vertically stacked label and secondary label, and an image (avatar) next to it.
Difference from the button is that this one takes an image instead of an icon and spaces the content proportionally, so that edge of the button nicely hugs the avatar image.
The button's colors default to using ColorScheme from the MaterialScope it's defined in, which defaults to dynamicColorScheme, meaning that the colors follow system theme if available on device. If not, or switched off by user, uses fallback ColorScheme defined in its MaterialScope.
import androidx.wear.protolayout.material3.avatarButton import androidx.wear.protolayout.material3.avatarImage import androidx.wear.protolayout.material3.button import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.modifiers.LayoutModifier import androidx.wear.protolayout.modifiers.clickable import androidx.wear.protolayout.modifiers.contentDescription import androidx.wear.protolayout.types.layoutString avatarButton( onClick = clickable(), modifier = LayoutModifier.contentDescription("Pill button"), avatarContent = { avatarImage("id") }, labelContent = { text("Primary label".layoutString) }, secondaryLabelContent = { text("Secondary label".layoutString) }, )
| Parameters | |
|---|---|
@NonNull ModifiersBuilders.Clickable onClick |
Associated |
@NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> labelContent |
The text slot for content displayed in this button. It is recommended to use default styling that is automatically provided by only calling |
@NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> avatarContent |
The avatar slot for content displayed in this button. It is recommended to use default styling that is automatically provided by only calling |
@NonNull LayoutModifier modifier |
Modifiers to set to this element. It's highly recommended to set a content description using |
Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> secondaryLabelContent |
The text slot for content displayed in this button. It is recommended to use default styling that is automatically provided by only calling |
@NonNull DimensionBuilders.ContainerDimension height |
The height of this button. It's highly recommended to set this to |
@NonNull ModifiersBuilders.Corner shape |
Defines the button's shape, in other words the corner radius for this button. If changing these to radius smaller than |
@NonNull ButtonColors colors |
The colors used for this button. If not set, |
@NonNull AvatarButtonStyle style |
The style which provides the attribute values required for constructing this pill shape button and its inner content. It also provides default style for the inner content, that can be overridden by each content slot. |
int horizontalAlignment |
The horizontal placement of the |
@NonNull ModifiersBuilders.Padding contentPadding |
The inner padding used to prevent inner content from being too close to the button's edge. It's highly recommended to keep the default. Only vertical values would be used, as horizontally elements are spaced out proportionally to the buttons width. |
button
public static final @NonNull LayoutElementBuilders.LayoutElement button(
@NonNull MaterialScope receiver,
@NonNull ModifiersBuilders.Clickable onClick,
@NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> labelContent,
@NonNull LayoutModifier modifier,
Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> secondaryLabelContent,
Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> iconContent,
@NonNull DimensionBuilders.ContainerDimension width,
@NonNull DimensionBuilders.ContainerDimension height,
@NonNull ModifiersBuilders.Corner shape,
@NonNull ButtonColors colors,
Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> backgroundContent,
@NonNull ButtonStyle style,
int horizontalAlignment,
@NonNull ModifiersBuilders.Padding contentPadding
)
Opinionated ProtoLayout Material3 pill shape button that offers up to three slots to take content representing vertically stacked label and secondary label, and an icon next to it.
The button's colors default to using ColorScheme from the MaterialScope it's defined in, which defaults to dynamicColorScheme, meaning that the colors follow system theme if available on device. If not, or switched off by user, uses fallback ColorScheme defined in its MaterialScope.
import androidx.wear.protolayout.DimensionBuilders.expand import androidx.wear.protolayout.material3.button import androidx.wear.protolayout.material3.icon import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.primaryLayout import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.modifiers.LayoutModifier import androidx.wear.protolayout.modifiers.clickable import androidx.wear.protolayout.modifiers.contentDescription import androidx.wear.protolayout.types.layoutString materialScope(context, deviceConfiguration) { primaryLayout( mainSlot = { button( onClick = clickable, modifier = LayoutModifier.contentDescription("Pill shape button"), width = expand(), height = expand(), labelContent = { text("First label".layoutString) }, secondaryLabelContent = { text("Second label".layoutString) }, iconContent = { icon("id") }, ) } ) }
import androidx.wear.protolayout.DimensionBuilders.expand import androidx.wear.protolayout.LayoutElementBuilders.Box import androidx.wear.protolayout.material3.button import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.primaryLayout import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.modifiers.LayoutModifier import androidx.wear.protolayout.modifiers.background import androidx.wear.protolayout.modifiers.clickable import androidx.wear.protolayout.modifiers.contentDescription materialScope(context, deviceConfiguration) { primaryLayout( mainSlot = { // Button with custom content inside button( onClick = clickable, modifier = LayoutModifier.contentDescription("Big button with image background") .background(colorScheme.primary), width = expand(), height = expand(), labelContent = { // This can be further built. Box.Builder().build() }, ) } ) }
| Parameters | |
|---|---|
@NonNull ModifiersBuilders.Clickable onClick |
Associated |
@NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> labelContent |
The text slot for content displayed in this button. It is recommended to use default styling that is automatically provided by only calling |
@NonNull LayoutModifier modifier |
Modifiers to set to this element. It's highly recommended to set a content description using |
Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> secondaryLabelContent |
The text slot for content displayed in this button. It is recommended to use default styling that is automatically provided by only calling |
Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> iconContent |
The icon slot for content displayed in this button. It is recommended to use default styling that is automatically provided by only calling |
@NonNull DimensionBuilders.ContainerDimension width |
The width of this button. It's highly recommended to set this to |
@NonNull DimensionBuilders.ContainerDimension height |
The height of this button. It's highly recommended to set this to |
@NonNull ModifiersBuilders.Corner shape |
Defines the button's shape, in other words the corner radius for this button. If changing these to radius smaller than |
@NonNull ButtonColors colors |
The colors used for this button. If not set, |
Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> backgroundContent |
The background object to be used behind the content in the button. It is recommended to use the default styling that is automatically provided by only calling |
@NonNull ButtonStyle style |
The style which provides the attribute values required for constructing this pill shape button and its inner content. It also provides default style for the inner content, that can be overridden by each content slot. |
int horizontalAlignment |
The horizontal placement of the |
@NonNull ModifiersBuilders.Padding contentPadding |
The inner padding used to prevent inner content from being too close to the button's edge. It's highly recommended to keep the default. |
compactButton
public static final @NonNull LayoutElementBuilders.LayoutElement compactButton(
@NonNull MaterialScope receiver,
@NonNull ModifiersBuilders.Clickable onClick,
@NonNull LayoutModifier modifier,
Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> labelContent,
Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> iconContent,
@NonNull DimensionBuilders.ContainerDimension width,
@NonNull ModifiersBuilders.Corner shape,
@NonNull ButtonColors colors,
int horizontalAlignment,
@NonNull ModifiersBuilders.Padding contentPadding
)
Opinionated ProtoLayout Material3 compact button that offers up to two slots to take horizontally stacked content representing an icon and text next to it.
The button's colors default to using ColorScheme from the MaterialScope it's defined in, which defaults to dynamicColorScheme, meaning that the colors follow system theme if available on device. If not, or switched off by user, uses fallback ColorScheme defined in its MaterialScope.
import androidx.wear.protolayout.DimensionBuilders.expand import androidx.wear.protolayout.material3.button import androidx.wear.protolayout.material3.compactButton import androidx.wear.protolayout.material3.icon import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.primaryLayout import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.modifiers.LayoutModifier import androidx.wear.protolayout.modifiers.clickable import androidx.wear.protolayout.modifiers.contentDescription import androidx.wear.protolayout.types.layoutString materialScope(context, deviceConfiguration) { primaryLayout( mainSlot = { compactButton( onClick = clickable, modifier = LayoutModifier.contentDescription("Compact button"), width = expand(), labelContent = { text("Action".layoutString) }, iconContent = { icon("id") }, ) } ) }
| Parameters | |
|---|---|
@NonNull ModifiersBuilders.Clickable onClick |
Associated |
@NonNull LayoutModifier modifier |
Modifiers to set to this element. It's highly recommended to set a content description using |
Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> labelContent |
The text slot for content displayed in this button. It is recommended to use default styling that is automatically provided by calling |
Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> iconContent |
The icon slot for content displayed in this button. It is recommended to use default styling that is automatically provided by only calling |
@NonNull DimensionBuilders.ContainerDimension width |
The width of this button. It's highly recommended to set this to |
@NonNull ModifiersBuilders.Corner shape |
Defines the button's shape, in other words the corner radius for this button. If changing these to radius smaller than |
@NonNull ButtonColors colors |
The colors used for this button. If not set, |
int horizontalAlignment |
The horizontal placement of the |
@NonNull ModifiersBuilders.Padding contentPadding |
The inner padding used to prevent inner content from being too close to the button's edge. It's highly recommended to keep the default. |
iconButton
public static final @NonNull LayoutElementBuilders.LayoutElement iconButton(
@NonNull MaterialScope receiver,
@NonNull ModifiersBuilders.Clickable onClick,
@NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> iconContent,
@NonNull LayoutModifier modifier,
@NonNull DimensionBuilders.ContainerDimension width,
@NonNull DimensionBuilders.ContainerDimension height,
@NonNull ModifiersBuilders.Corner shape,
@NonNull ButtonColors colors,
@NonNull IconButtonStyle style,
@NonNull ModifiersBuilders.Padding contentPadding
)
Opinionated ProtoLayout Material3 icon button that offers a single slot to take content representing icon, for example icon.
The button is usually either a circular shape with the same width and height, or highly recommended stadium shape occupying available space with width and height set to expand or weight, usually arranged with the buttonGroup.
The button's colors default to using ColorScheme from the MaterialScope it's defined in, which defaults to dynamicColorScheme, meaning that the colors follow system theme if available on device. If not, or switched off by user, uses fallback ColorScheme defined in its MaterialScope.
import androidx.wear.protolayout.DimensionBuilders.expand import androidx.wear.protolayout.material3.button import androidx.wear.protolayout.material3.buttonGroup import androidx.wear.protolayout.material3.icon import androidx.wear.protolayout.material3.iconButton import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.primaryLayout import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.material3.textButton import androidx.wear.protolayout.modifiers.LayoutModifier import androidx.wear.protolayout.modifiers.background import androidx.wear.protolayout.modifiers.clickable import androidx.wear.protolayout.modifiers.contentDescription import androidx.wear.protolayout.types.layoutString materialScope(context, deviceConfiguration) { primaryLayout( mainSlot = { buttonGroup { buttonGroupItem { iconButton( onClick = clickable, modifier = LayoutModifier.contentDescription( "Big button with image background" ), width = expand(), height = expand(), iconContent = { icon("id1") }, ) } buttonGroupItem { iconButton( onClick = clickable, modifier = LayoutModifier.contentDescription( "Big button with image background" ), width = expand(), height = expand(), shape = shapes.large, iconContent = { icon("id2") }, ) } buttonGroupItem { textButton( onClick = clickable, modifier = LayoutModifier.contentDescription( "Big button with image background" ), width = expand(), height = expand(), shape = shapes.large, labelContent = { text("Dec".layoutString) }, ) } } } ) }
| Parameters | |
|---|---|
@NonNull ModifiersBuilders.Clickable onClick |
Associated |
@NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> iconContent |
The icon slot for content displayed in this button. It is recommended to use default styling that is automatically provided by only calling |
@NonNull LayoutModifier modifier |
Modifiers to set to this element. It's highly recommended to set a content description using |
@NonNull DimensionBuilders.ContainerDimension width |
The width of this button. It's highly recommended to set this to |
@NonNull DimensionBuilders.ContainerDimension height |
The height of this button. It's highly recommended to set this to |
@NonNull ModifiersBuilders.Corner shape |
Defines the button's shape, in other words the corner radius for this button. If changing these to radius smaller than |
@NonNull ButtonColors colors |
The colors used for this button. If not set, |
@NonNull IconButtonStyle style |
The style which provides the attribute values required for constructing this icon button and its inner content. It also provides default style for the inner content, that can be overridden by each content slot. |
@NonNull ModifiersBuilders.Padding contentPadding |
The inner padding used to prevent inner content from being too close to the button's edge. It's highly recommended to keep the default. |
imageButton
public static final @NonNull LayoutElementBuilders.LayoutElement imageButton(
@NonNull MaterialScope receiver,
@NonNull ModifiersBuilders.Clickable onClick,
@NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> backgroundContent,
@NonNull LayoutModifier modifier,
@NonNull DimensionBuilders.ContainerDimension width,
@NonNull DimensionBuilders.ContainerDimension height
)
ProtoLayout Material3 clickable image button that doesn't offer additional slots, only image (for example backgroundImage as a background).
The button is usually stadium or circle shaped with fully rounded corners by default. It is highly recommended to set its width and height to fill the available space, by expand or weight for optimal experience across different screen sizes, and use buttonGroup to arrange them.
import androidx.wear.protolayout.DimensionBuilders.expand import androidx.wear.protolayout.material3.backgroundImage import androidx.wear.protolayout.material3.button import androidx.wear.protolayout.material3.imageButton import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.primaryLayout import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.modifiers.LayoutModifier import androidx.wear.protolayout.modifiers.background import androidx.wear.protolayout.modifiers.clickable import androidx.wear.protolayout.modifiers.contentDescription materialScope(context, deviceConfiguration) { primaryLayout( mainSlot = { imageButton( onClick = clickable, modifier = LayoutModifier.contentDescription("Big button with image background"), width = expand(), height = expand(), backgroundContent = { backgroundImage(protoLayoutResourceId = "id") }, ) } ) }
| Parameters | |
|---|---|
@NonNull ModifiersBuilders.Clickable onClick |
Associated |
@NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> backgroundContent |
The background object to be used behind the content in the button. It is recommended to use the default styling that is automatically provided by only calling |
@NonNull LayoutModifier modifier |
Modifiers to set to this element. It's highly recommended to set a content description using |
@NonNull DimensionBuilders.ContainerDimension width |
The width of this button. It's highly recommended to set this to |
@NonNull DimensionBuilders.ContainerDimension height |
The height of this button. It's highly recommended to set this to |
textButton
public static final @NonNull LayoutElementBuilders.LayoutElement textButton(
@NonNull MaterialScope receiver,
@NonNull ModifiersBuilders.Clickable onClick,
@NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> labelContent,
@NonNull LayoutModifier modifier,
@NonNull DimensionBuilders.ContainerDimension width,
@NonNull DimensionBuilders.ContainerDimension height,
@NonNull ModifiersBuilders.Corner shape,
@NonNull ButtonColors colors,
@NonNull TextButtonStyle style,
@NonNull ModifiersBuilders.Padding contentPadding
)
Opinionated ProtoLayout Material3 text button that offers a single slot to take content representing short text, for example text.
The button is usually either a circular shape with the same width and height, or highly recommended stadium shape occupying available space with width and height set to expand or weight, usually arranged with the buttonGroup.
The button's colors default to using ColorScheme from the MaterialScope it's defined in, which defaults to dynamicColorScheme, meaning that the colors follow system theme if available on device. If not, or switched off by user, uses fallback ColorScheme defined in its MaterialScope.
import androidx.wear.protolayout.DimensionBuilders.expand import androidx.wear.protolayout.material3.button import androidx.wear.protolayout.material3.buttonGroup import androidx.wear.protolayout.material3.icon import androidx.wear.protolayout.material3.iconButton import androidx.wear.protolayout.material3.materialScope import androidx.wear.protolayout.material3.primaryLayout import androidx.wear.protolayout.material3.text import androidx.wear.protolayout.material3.textButton import androidx.wear.protolayout.modifiers.LayoutModifier import androidx.wear.protolayout.modifiers.background import androidx.wear.protolayout.modifiers.clickable import androidx.wear.protolayout.modifiers.contentDescription import androidx.wear.protolayout.types.layoutString materialScope(context, deviceConfiguration) { primaryLayout( mainSlot = { buttonGroup { buttonGroupItem { iconButton( onClick = clickable, modifier = LayoutModifier.contentDescription( "Big button with image background" ), width = expand(), height = expand(), iconContent = { icon("id1") }, ) } buttonGroupItem { iconButton( onClick = clickable, modifier = LayoutModifier.contentDescription( "Big button with image background" ), width = expand(), height = expand(), shape = shapes.large, iconContent = { icon("id2") }, ) } buttonGroupItem { textButton( onClick = clickable, modifier = LayoutModifier.contentDescription( "Big button with image background" ), width = expand(), height = expand(), shape = shapes.large, labelContent = { text("Dec".layoutString) }, ) } } } ) }
| Parameters | |
|---|---|
@NonNull ModifiersBuilders.Clickable onClick |
Associated |
@NonNull Function1<@NonNull MaterialScope, @NonNull LayoutElementBuilders.LayoutElement> labelContent |
The text slot for content displayed in this button. It is recommended to use default styling that is automatically provided by only calling |
@NonNull LayoutModifier modifier |
Modifiers to set to this element. It's highly recommended to set a content description using |
@NonNull DimensionBuilders.ContainerDimension width |
The width of this button. It's highly recommended to set this to |
@NonNull DimensionBuilders.ContainerDimension height |
The height of this button. It's highly recommended to set this to |
@NonNull ModifiersBuilders.Corner shape |
Defines the button's shape, in other words the corner radius for this button. If changing these to radius smaller than |
@NonNull ButtonColors colors |
The colors used for this button. If not set, |
@NonNull TextButtonStyle style |
The style which provides the attribute values required for constructing this text button and its inner content. It also provides default style for the inner content, that can be overridden by each content slot. |
@NonNull ModifiersBuilders.Padding contentPadding |
The inner padding used to prevent inner content from being too close to the button's edge. It's highly recommended to keep the default. |