Button.Builder

Added in 1.1.0
Deprecated in 1.2.0

public final class Button.Builder implements LayoutElementBuilders.LayoutElement.Builder


Builder class for Button.

Summary

Public constructors

Builder(
    @NonNull Context context,
    @NonNull ModifiersBuilders.Clickable clickable
)

Creates a builder for the Button from the given content.

Public methods

@NonNull Button

Constructs and returns Button with the provided field and look.

@NonNull Button.Builder

Sets the colors for the Button.

@NonNull Button.Builder

Sets the content description for the Button.

@NonNull Button.Builder

Sets the custom content for this Button.

@NonNull Button.Builder
setIconContent(@NonNull 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.

@NonNull Button.Builder
setIconContent(
    @NonNull String imageResourceId,
    @NonNull DimensionBuilders.DpProp size
)

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

@NonNull Button.Builder
setImageContent(@NonNull String imageResourceId)

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

@NonNull Button.Builder

Sets the size for the Button.

@NonNull Button.Builder
setSize(@Dimension(unit = 0) float size)

Sets the size for the Button.

@NonNull Button.Builder

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

@NonNull Button.Builder
setTextContent(@NonNull String text, int typographyName)

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

Public constructors

Builder

Added in 1.1.0
Deprecated in 1.2.0
public Builder(
    @NonNull Context context,
    @NonNull ModifiersBuilders.Clickable clickable
)

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

Parameters
@NonNull Context context

The application's context.

@NonNull ModifiersBuilders.Clickable clickable

Associated androidx.wear.tiles.ModifiersBuilders.Clickable for click events. When the Button is clicked it will fire the associated action.

Public methods

build

Added in 1.1.0
Deprecated in 1.2.0
public @NonNull Button build()

Constructs and returns Button with the provided field and look.

setButtonColors

Added in 1.1.0
Deprecated in 1.2.0
public @NonNull Button.Builder setButtonColors(@NonNull ButtonColors buttonColors)

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

setContentDescription

Added in 1.1.0
Deprecated in 1.2.0
public @NonNull Button.Builder setContentDescription(@NonNull CharSequence contentDescription)

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

setCustomContent

Added in 1.1.0
Deprecated in 1.2.0
public @NonNull Button.Builder setCustomContent(@NonNull LayoutElementBuilders.LayoutElement content)

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

setIconContent

Added in 1.1.0
Deprecated in 1.2.0
public @NonNull Button.Builder setIconContent(@NonNull 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.

setIconContent

Added in 1.1.0
Deprecated in 1.2.0
public @NonNull Button.Builder setIconContent(
    @NonNull String imageResourceId,
    @NonNull 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.

setImageContent

Added in 1.1.0
Deprecated in 1.2.0
public @NonNull Button.Builder setImageContent(@NonNull String imageResourceId)

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

setSize

Added in 1.1.0
Deprecated in 1.2.0
public @NonNull Button.Builder setSize(@NonNull DimensionBuilders.DpProp size)

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

setSize

Added in 1.1.0
Deprecated in 1.2.0
public @NonNull Button.Builder setSize(@Dimension(unit = 0) float size)

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

setTextContent

Added in 1.1.0
Deprecated in 1.2.0
public @NonNull Button.Builder setTextContent(@NonNull String text)

Sets the content of this Button to be the given text with the default font for the set size (for the DEFAULT_SIZE, LARGE_SIZE and EXTRA_LARGE_SIZE is TYPOGRAPHY_TITLE2, TYPOGRAPHY_TITLE1 and 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.

setTextContent

Added in 1.1.0
Deprecated in 1.2.0
public @NonNull Button.Builder setTextContent(@NonNull 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 setCustomContent with component. Any previously added content will be overridden. Text should contain no more than 3 characters, otherwise it will overflow from the edges.