Chip.Builder
public final class Chip.Builder
Builder class for Chip.
Summary
Public constructors |
|---|
Builder(Creates a builder for the |
Public methods |
|
|---|---|
@NonNull Chip |
build()Constructs and returns |
@NonNull Chip.Builder |
setChipColors(@NonNull ChipColors chipColors)Sets the colors for the |
@NonNull Chip.Builder |
setContentDescription(@NonNull CharSequence contentDescription)Sets the static content description for the |
@NonNull Chip.Builder |
setContentDescription(Sets the content description for the |
@NonNull Chip.Builder |
Sets the custom content for the |
@NonNull Chip.Builder |
setHorizontalAlignment(int horizontalAlignment)Sets the horizontal alignment in the chip. |
@NonNull Chip.Builder |
setIconContent(@NonNull String imageResourceId)Sets the icon for the |
@NonNull Chip.Builder |
setPrimaryLabelContent(@NonNull String primaryLabel)Sets the primary label for the |
@NonNull Chip.Builder |
setSecondaryLabelContent(@NonNull String secondaryLabel)Sets the secondary label for the |
@NonNull Chip.Builder |
Sets the width of |
@NonNull Chip.Builder |
Sets the width of |
Public constructors
Builder
public Builder(
@NonNull Context context,
@NonNull ModifiersBuilders.Clickable clickable,
@NonNull DeviceParametersBuilders.DeviceParameters deviceParameters
)
Creates a builder for the Chip with associated action. It is required to add content later with setters.
| Parameters | |
|---|---|
@NonNull Context context |
The application's context. |
@NonNull ModifiersBuilders.Clickable clickable |
Associated |
@NonNull DeviceParametersBuilders.DeviceParameters deviceParameters |
The device parameters used to derive defaults for this Chip. |
Public methods
build
public @NonNull Chip build()
Constructs and returns Chip with the provided content and look.
setChipColors
public @NonNull Chip.Builder setChipColors(@NonNull ChipColors chipColors)
Sets the colors for the Chip. If set, getBackgroundColor will be used for the background of the button, getContentColor for main text, getSecondaryContentColor for label text and getIconColor will be used as color for the icon itself. If not set, PRIMARY_COLORS will be used.
setContentDescription
public @NonNull Chip.Builder setContentDescription(@NonNull CharSequence contentDescription)
Sets the static content description for the Chip. It is highly recommended to provide this for chip containing icon.
setContentDescription
public @NonNull Chip.Builder setContentDescription(
@NonNull TypeBuilders.StringProp contentDescription
)
Sets the content description for the Chip. It is highly recommended to provide this for chip containing icon.
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 Chip.Builder setCustomContent(@NonNull LayoutElementBuilders.LayoutElement content)
Sets the custom content for the Chip. Any previously added content will be overridden.
setHorizontalAlignment
public @NonNull Chip.Builder setHorizontalAlignment(int horizontalAlignment)
Sets the horizontal alignment in the chip. It is strongly recommended that the content of the chip is start-aligned if there is more than primary text in it. By default, HORIZONTAL_ALIGN_CENTER will be used when only a primary label is present. Otherwise HORIZONTAL_ALIGN_START will be used.
setIconContent
public @NonNull Chip.Builder setIconContent(@NonNull String imageResourceId)
Sets the icon for the Chip. Any previously added custom content will be overridden. Provided icon will be tinted to the given content color from ChipColors. This icon should be image with chosen alpha channel and not an actual image. If icon is set, primary label must be set too with setPrimaryLabelContent.
setPrimaryLabelContent
public @NonNull Chip.Builder setPrimaryLabelContent(@NonNull String primaryLabel)
Sets the primary label for the Chip. Any previously added custom content will be overridden. Primary label can be on 1 or 2 lines, depending on the length and existence of secondary label.
setSecondaryLabelContent
public @NonNull Chip.Builder setSecondaryLabelContent(@NonNull String secondaryLabel)
Sets the secondary label for the Chip. Any previously added custom content will be overridden. If secondary label is set, primary label must be set too with setPrimaryLabelContent.
setWidth
public @NonNull Chip.Builder setWidth(@NonNull DimensionBuilders.ContainerDimension width)
Sets the width of Chip. If not set, default value will be set to fill the screen.