Chip
public class Chip implements LayoutElementBuilders.LayoutElement
ProtoLayout component Chip
that represents clickable object with the text, optional label and optional icon or with custom content.
The Chip is Stadium shape that has a max height designed to take no more than two lines of text of TYPOGRAPHY_BUTTON
style and with minimum tap target to meet accessibility requirements. The Chip
can have an icon horizontally parallel to the two lines of text. Width of chip can very, and the recommended size is screen dependent with the recommended margin being applied.
The recommended set of ChipColors
styles can be obtained from ChipDefaults
., e.g. PRIMARY_COLORS
to get a color scheme for a primary Chip
.
When accessing the contents of a container for testing, note that this element can't be simply casted back to the original type, i.e.:
Chip chip = new Chip... Box box = new Box.Builder().addContent(chip).build(); Chip myChip = (Chip) box.getContents().get(0);
To be able to get Chip
object from any layout element, fromLayoutElement
method should be used, i.e.:
Chip myChip = Chip.fromLayoutElement(box.getContents().get(0));
See also | |
---|---|
setContent |
if this Chip is used inside of |
Summary
Nested types |
---|
public final class Chip.Builder Builder class for |
Public methods |
|
---|---|
static @Nullable Chip |
Returns Chip object from the given LayoutElement (e.g. one retrieved from a container's content with |
@NonNull ChipColors |
Returns chip colors of this Chip. |
@NonNull ModifiersBuilders.Clickable |
Returns click event action associated with this Chip. |
@Nullable TypeBuilders.StringProp |
Returns content description of this Chip. |
@Nullable LayoutElementBuilders.LayoutElement |
Returns custom content from this Chip if it has been added. |
@NonNull DimensionBuilders.ContainerDimension |
Returns the visible height of this Chip. |
int |
Returns the horizontal alignment of the content in this Chip. |
@Nullable String |
Returns icon id from this Chip if it has been added. |
@Nullable String |
Returns primary label from this Chip if it has been added. |
@Nullable String |
Returns secondary label from this Chip if it has been added. |
@NonNull DimensionBuilders.ContainerDimension |
getWidth() Returns width of this Chip. |
Public methods
fromLayoutElement
public static @Nullable Chip fromLayoutElement(@NonNull LayoutElementBuilders.LayoutElement element)
Returns Chip object from the given LayoutElement (e.g. one retrieved from a container's content with container.getContents().get(index)
) if that element can be converted to Chip. Otherwise, it will return null.
getChipColors
public @NonNull ChipColors getChipColors()
Returns chip colors of this Chip.
getClickable
public @NonNull ModifiersBuilders.Clickable getClickable()
Returns click event action associated with this Chip.
getContentDescription
public @Nullable TypeBuilders.StringProp getContentDescription()
Returns content description of this Chip.
getCustomContent
public @Nullable LayoutElementBuilders.LayoutElement getCustomContent()
Returns custom content from this Chip if it has been added. Otherwise, it returns null.
getHeight
public @NonNull DimensionBuilders.ContainerDimension getHeight()
Returns the visible height of this Chip.
getHorizontalAlignment
public int getHorizontalAlignment()
Returns the horizontal alignment of the content in this Chip.
getIconContent
public @Nullable String getIconContent()
Returns icon id from this Chip if it has been added. Otherwise, it returns null.
getPrimaryLabelContent
public @Nullable String getPrimaryLabelContent()
Returns primary label from this Chip if it has been added. Otherwise, it returns null.
getSecondaryLabelContent
public @Nullable String getSecondaryLabelContent()
Returns secondary label from this Chip if it has been added. Otherwise, it returns null.
getWidth
public @NonNull DimensionBuilders.ContainerDimension getWidth()
Returns width of this Chip.