public final class

Button.Builder

extends java.lang.Object

implements LayoutElementBuilders.LayoutElement.Builder

 java.lang.Object

↳androidx.wear.protolayout.material.Button.Builder

Overview

Builder class for Button.

Summary

Constructors
publicBuilder(Context context, ModifiersBuilders.Clickable clickable)

Creates a builder for the Button from the given content.

Methods
public Buttonbuild()

Constructs and returns Button with the provided field and look.

public Button.BuildersetButtonColors(ButtonColors buttonColors)

Sets the colors for the Button.

public Button.BuildersetContentDescription(java.lang.CharSequence contentDescription)

Sets the static content description for the Button.

public Button.BuildersetContentDescription(TypeBuilders.StringProp contentDescription)

Sets the content description for the Button.

public Button.BuildersetCustomContent(LayoutElementBuilders.LayoutElement content)

Sets the custom content for this Button.

public Button.BuildersetIconContent(java.lang.String imageResourceId)

Sets the content of this Button to be the given icon with the default size that is half of the set size of the button.

public Button.BuildersetIconContent(java.lang.String imageResourceId, DimensionBuilders.DpProp size)

Sets the content of this Button to be the given icon with the given size.

public Button.BuildersetImageContent(java.lang.String imageResourceId)

Sets the content of this Button to be the given image, i.e.

public Button.BuildersetSize(DimensionBuilders.DpProp size)

Sets the size for the Button.

public Button.BuildersetSize(float size)

Sets the size for the Button.

public Button.BuildersetTextContent(java.lang.String text)

Sets the content of this Button to be the given text with the default font for the set size (for the ButtonDefaults.DEFAULT_SIZE, ButtonDefaults.LARGE_SIZE and ButtonDefaults.EXTRA_LARGE_SIZE is Typography.TYPOGRAPHY_TITLE2, Typography.TYPOGRAPHY_TITLE1 and Typography.TYPOGRAPHY_DISPLAY3 respectively).

public Button.BuildersetTextContent(java.lang.String text, int typographyName)

Sets the content of this Button to be the given text with the given font.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(Context context, ModifiersBuilders.Clickable clickable)

Creates a builder for the Button from the given content. Custom content should be later set with one of the following Button.Builder.setIconContent(String), Button.Builder, Button.Builder.setTextContent(String), Button.Builder.setTextContent(String, int) or Button.Builder.setImageContent(String).

Parameters:

context: The application's context.
clickable: Associated ModifiersBuilders.Clickable for click events. When the Button is clicked it will fire the associated action.

Methods

public Button.Builder setContentDescription(java.lang.CharSequence contentDescription)

Sets the static content description for the Button. It is highly recommended to provide this for button containing icon or image.

public Button.Builder setContentDescription(TypeBuilders.StringProp contentDescription)

Sets the content description for the Button. It is highly recommended to provide this for button containing icon or image.

While this field is statically accessible from 1.0, it's only bindable since version 1.2 and renderers supporting version 1.2 will use the dynamic value (if set).

Sets the size for the Button. Strongly recommended values are ButtonDefaults.DEFAULT_SIZE, ButtonDefaults.LARGE_SIZE and ButtonDefaults.EXTRA_LARGE_SIZE. If not set, ButtonDefaults.DEFAULT_SIZE will be used.

public Button.Builder setSize(float size)

Sets the size for the Button. Strongly recommended values are ButtonDefaults.DEFAULT_SIZE, ButtonDefaults.LARGE_SIZE and ButtonDefaults.EXTRA_LARGE_SIZE. If not set, ButtonDefaults.DEFAULT_SIZE will be used.

public Button.Builder setButtonColors(ButtonColors buttonColors)

Sets the colors for the Button. If not set, ButtonDefaults.PRIMARY_COLORS will be used.

Note: The content color will be ignored (and won't be returned by the getter) if the Button content is an image.

public Button.Builder setCustomContent(LayoutElementBuilders.LayoutElement content)

Sets the custom content for this Button. Any previously added content will be overridden.

public Button.Builder setIconContent(java.lang.String imageResourceId, DimensionBuilders.DpProp size)

Sets the content of this Button to be the given icon with the given size. Any previously added content will be overridden. Provided icon will be tinted to the given content color from ButtonColors and with the given size. This icon should be image with chosen alpha channel and not an actual image.

public Button.Builder setIconContent(java.lang.String imageResourceId)

Sets the content of this Button to be the given icon with the default size that is half of the set size of the button. Any previously added content will be overridden. Provided icon will be tinted to the given content color from ButtonColors. This icon should be image with chosen alpha channel and not an actual image.

public Button.Builder setTextContent(java.lang.String text)

Sets the content of this Button to be the given text with the default font for the set size (for the ButtonDefaults.DEFAULT_SIZE, ButtonDefaults.LARGE_SIZE and ButtonDefaults.EXTRA_LARGE_SIZE is Typography.TYPOGRAPHY_TITLE2, Typography.TYPOGRAPHY_TITLE1 and Typography.TYPOGRAPHY_DISPLAY3 respectively). Any previously added content will be overridden. Text should contain no more than 3 characters, otherwise it will overflow from the edges.

public Button.Builder setTextContent(java.lang.String text, int typographyName)

Sets the content of this Button to be the given text with the given font. If you need more font related customization, consider using Button.Builder.setCustomContent(LayoutElementBuilders.LayoutElement) with Text component. Any previously added content will be overridden. Text should contain no more than 3 characters, otherwise it will overflow from the edges.

public Button.Builder setImageContent(java.lang.String imageResourceId)

Sets the content of this Button to be the given image, i.e. contacts photo. Any previously added content will be overridden.

public Button build()

Constructs and returns Button with the provided field and look.