public class CompactChip implements LayoutElementBuilders.LayoutElement


ProtoLayout component CompactChip that represents clickable object with the text.

The CompactChip is Stadium shape and has a max height designed to take no more than one line of text of TYPOGRAPHY_CAPTION1 style with included margin for tap target to meet accessibility requirements. Width of the chip is adjustable to the text size.

The recommended set of ChipColors styles can be obtained from ChipDefaults., e.g. COMPACT_PRIMARY_COLORS to get a color scheme for a primary .

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.:

CompactChip chip = new CompactChip...
Box box = new Box.Builder().addContent(chip).build();

CompactChip myChip = (CompactChip) box.getContents().get(0);
will fail.

To be able to get CompactChip object from any layout element, fromLayoutElement method should be used, i.e.:

CompactChip myChip = CompactChip.fromLayoutElement(box.getContents().get(0));

Summary

Nested types

public final class CompactChip.Builder

Builder class for CompactChip.

Public methods

static @Nullable CompactChip

Returns CompactChip 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 CompactChip.

@NonNull ChipColors

Returns chip color of this Chip.

@NonNull ModifiersBuilders.Clickable

Returns click event action associated with this Chip.

@Nullable TypeBuilders.StringProp

Returns content description of this CompactChip.

@Nullable String

Returns icon id from this CompactChip if it has been added.

@NonNull String

Returns text content of this Chip if it was set.

boolean

Returns whether the text content of this Chip was set.

Public methods

fromLayoutElement

Added in 1.0.0
public static @Nullable CompactChip fromLayoutElement(@NonNull LayoutElementBuilders.LayoutElement element)

Returns CompactChip 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 CompactChip. Otherwise, it will return null.

getChipColors

Added in 1.0.0
public @NonNull ChipColors getChipColors()

Returns chip color of this Chip.

getClickable

Added in 1.0.0
public @NonNull ModifiersBuilders.Clickable getClickable()

Returns click event action associated with this Chip.

getContentDescription

Added in 1.2.0
public @Nullable TypeBuilders.StringProp getContentDescription()

Returns content description of this CompactChip.

getIconContent

Added in 1.0.0
public @Nullable String getIconContent()

Returns icon id from this CompactChip if it has been added. Otherwise, it returns null.

getText

Added in 1.0.0
public @NonNull String getText()

Returns text content of this Chip if it was set. If the text content wasn't set (either with setTextContent or constructor, this method will return an empty String. Whether text content exists on this Chip, that can be checked with hasText.

hasText

Added in 1.2.0
public boolean hasText()

Returns whether the text content of this Chip was set.