# CompactChip

# CompactChip

Artifact:[androidx.wear.protolayout:protolayout-material](https://developer.android.com/jetpack/androidx/releases/wear-protolayout)  
[View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/material/CompactChip.java+class:androidx.wear.protolayout.material.CompactChip)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/wear/protolayout/material/CompactChip "View this page in Java")

<br />

```
class CompactChip : LayoutElementBuilders.LayoutElement
```

<br />

*** ** * ** ***

ProtoLayout component[CompactChip](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/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](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Typography#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](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ChipColors)styles can be obtained from[ChipDefaults](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ChipDefaults)., e.g.[COMPACT_PRIMARY_COLORS](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ChipDefaults#COMPACT_PRIMARY_COLORS())to get a color scheme for a primary[CompactChip](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip).

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

```kotlin
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](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip)object from any layout element,[fromLayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip#fromLayoutElement(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))method should be used, i.e.:  

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

## Summary

|                                                                                                                          ### Nested types                                                                                                                           |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `class `[CompactChip.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip.Builder) Builder class for[CompactChip](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip). |

|                                                        ### Public functions                                                         |
|-------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[CompactChip](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip)`?`       | [fromLayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip#fromLayoutElement(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))`(element: `[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`)` 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. |
| [ChipColors](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ChipColors)                          | [getChipColors](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip#getChipColors())`()` Returns chip color of this Chip.                                                                                                                                                                                                                                                                                                                                                                                                     |
| [ModifiersBuilders.Clickable](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ModifiersBuilders.Clickable) | [getClickable](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip#getClickable())`()` Returns click event action associated with this Chip.                                                                                                                                                                                                                                                                                                                                                                                  |
| [TypeBuilders.StringProp](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/TypeBuilders.StringProp)`?`      | [getContentDescription](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip#getContentDescription())`()` Returns content description of this CompactChip.                                                                                                                                                                                                                                                                                                                                                                     |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?`                                                | [getIconContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip#getIconContent())`()` Returns icon id from this CompactChip if it has been added.                                                                                                                                                                                                                                                                                                                                                                        |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                                   | [getText](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip#getText())`()` Returns text content of this Chip if it was set.                                                                                                                                                                                                                                                                                                                                                                                                 |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                 | [hasText](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip#hasText())`()` Returns whether the text content of this Chip was set.                                                                                                                                                                                                                                                                                                                                                                                           |

## Public functions

### fromLayoutElement

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)  

```
java-static fun fromLayoutElement(element: LayoutElementBuilders.LayoutElement): 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. Otherwise, it will return null.  

### getChipColors

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)  

```
fun getChipColors(): ChipColors
```

Returns chip color of this Chip.  

### getClickable

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)  

```
fun getClickable(): ModifiersBuilders.Clickable
```

Returns click event action associated with this Chip.  

### getContentDescription

Added in[1.2.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.2.0)  

```
fun getContentDescription(): TypeBuilders.StringProp?
```

Returns content description of this CompactChip.  

### getIconContent

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)  

```
fun getIconContent(): String?
```

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

### getText

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)  

```
fun getText(): String
```

Returns text content of this Chip if it was set. If the text content wasn't set (either with[setTextContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip.Builder#setTextContent(java.lang.String))or constructor, this method will return an empty String. Whether text content exists on this Chip, that can be checked with[hasText](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip#hasText()).  

### hasText

Added in[1.2.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.2.0)  

```
fun hasText(): Boolean
```

Returns whether the text content of this Chip was set.