Button.Builder
public final class Button.Builder
Builder class for Button.
Summary
Public constructors |
|---|
Builder(Creates a builder for the |
Public methods |
|
|---|---|
@NonNull Button |
build()Constructs and returns |
@NonNull Button.Builder |
setButtonColors(@NonNull ButtonColors buttonColors)Sets the colors for the |
@NonNull Button.Builder |
setContentDescription(@NonNull CharSequence contentDescription)Sets the static content description for the |
@NonNull Button.Builder |
setContentDescription(Sets the content description for the |
@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(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 |
@NonNull Button.Builder |
Sets the size for the |
@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 |
@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
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, setIconContent, setTextContent, setTextContent or setImageContent.
| Parameters | |
|---|---|
@NonNull Context context |
The application's context. |
@NonNull ModifiersBuilders.Clickable clickable |
Associated |
Public methods
build
public @NonNull Button build()
Constructs and returns Button with the provided field and look.
setButtonColors
public @NonNull Button.Builder setButtonColors(@NonNull ButtonColors buttonColors)
Sets the colors for the Button. If not set, 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.
setContentDescription
public @NonNull Button.Builder setContentDescription(@NonNull CharSequence contentDescription)
Sets the static content description for the Button. It is highly recommended to provide this for button containing icon or image.
setContentDescription
public @NonNull Button.Builder setContentDescription(
@NonNull 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).
setCustomContent
public @NonNull Button.Builder setCustomContent(@NonNull LayoutElementBuilders.LayoutElement content)
Sets the custom content for this Button. Any previously added content will be overridden.
setIconContent
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
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
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
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
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
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
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 Text component. Any previously added content will be overridden. Text should contain no more than 3 characters, otherwise it will overflow from the edges.