# Chip

# Chip

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/Chip.java+class:androidx.wear.protolayout.material.Chip)  
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/Chip "View this page in Java")

<br />

```
class Chip : LayoutElementBuilders.LayoutElement
```

<br />

*** ** * ** ***

ProtoLayout component[Chip](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/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](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Typography#TYPOGRAPHY_BUTTON())style and with minimum tap target to meet accessibility requirements. The[Chip](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/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](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.[PRIMARY_COLORS](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ChipDefaults#PRIMARY_COLORS())to get a color scheme for a primary[Chip](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/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.:  

```kotlin
Chip chip = new Chip...
Box box = new Box.Builder().addContent(chip).build();

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

To be able to get[Chip](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Chip)object from any layout element,[fromLayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Chip#fromLayoutElement(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))method should be used, i.e.:  

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

|                                                                                                See also                                                                                                 |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [setContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder#setContent(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement)) | if this Chip is used inside of[androidx.wear.protolayout.material.layouts.PrimaryLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout). |

## Summary

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

|                                                                  ### Public functions                                                                  |
|--------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Chip](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Chip)`?`                                        | [fromLayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Chip#fromLayoutElement(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))`(element: `[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`)` 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. |
| [ChipColors](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ChipColors)                                             | [getChipColors](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Chip#getChipColors())`()` Returns chip colors 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/Chip#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/Chip#getContentDescription())`()` Returns content description of this Chip.                                                                                                                                                                                                                                                                                                                                                              |
| [LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`?` | [getCustomContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Chip#getCustomContent())`()` Returns custom content from this Chip if it has been added.                                                                                                                                                                                                                                                                                                                                                      |
| [DimensionBuilders.ContainerDimension](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/DimensionBuilders.ContainerDimension)  | [getHeight](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Chip#getHeight())`()` Returns the visible height of this Chip.                                                                                                                                                                                                                                                                                                                                                                                       |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                            | [getHorizontalAlignment](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Chip#getHorizontalAlignment())`()` Returns the horizontal alignment of the content in this Chip.                                                                                                                                                                                                                                                                                                                                        |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?`                                                                   | [getIconContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Chip#getIconContent())`()` Returns icon id from this Chip if it has been added.                                                                                                                                                                                                                                                                                                                                                                 |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?`                                                                   | [getPrimaryLabelContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Chip#getPrimaryLabelContent())`()` Returns primary label from this Chip if it has been added.                                                                                                                                                                                                                                                                                                                                           |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?`                                                                   | [getSecondaryLabelContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Chip#getSecondaryLabelContent())`()` Returns secondary label from this Chip if it has been added.                                                                                                                                                                                                                                                                                                                                     |
| [DimensionBuilders.ContainerDimension](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/DimensionBuilders.ContainerDimension)  | [getWidth](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Chip#getWidth())`()` Returns width of this Chip.                                                                                                                                                                                                                                                                                                                                                                                                      |

## 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): Chip?
```

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

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

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

Returns chip colors 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.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)  

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

Returns content description of this Chip.  

### getCustomContent

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

```
fun getCustomContent(): LayoutElementBuilders.LayoutElement?
```

Returns custom content from this Chip if it has been added. Otherwise, it returns null.  

### getHeight

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

```
fun getHeight(): DimensionBuilders.ContainerDimension
```

Returns the visible height of this Chip.  

### getHorizontalAlignment

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

```
fun getHorizontalAlignment(): Int
```

Returns the horizontal alignment of the content in this Chip.  

### 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 Chip if it has been added. Otherwise, it returns null.  

### getPrimaryLabelContent

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

```
fun getPrimaryLabelContent(): String?
```

Returns primary label from this Chip if it has been added. Otherwise, it returns null.  

### getSecondaryLabelContent

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

```
fun getSecondaryLabelContent(): String?
```

Returns secondary label from this Chip if it has been added. Otherwise, it returns null.  

### getWidth

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

```
fun getWidth(): DimensionBuilders.ContainerDimension
```

Returns width of this Chip.