# Chip.Builder

Artifact: [androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app) [View Source](https://cs.android.com/search?q=file:androidx/car/app/model/Chip.java+class:androidx.car.app.model.Chip.Builder) Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.8.0)

*** ** * ** ***


```
class Chip.Builder
```

<br />

*** ** * ** ***

A builder of `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#Builder()()` |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#build()()` Constructs the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip` defined by this builder. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setEndIcon(androidx.car.app.model.CarIcon)(endIcon: https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon)` Sets the icon to display at the end of the chip. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setOnClickListener(androidx.car.app.model.OnClickListener)(onClickListener: https://developer.android.com/reference/kotlin/androidx/car/app/model/OnClickListener)` Sets the `https://developer.android.com/reference/kotlin/androidx/car/app/model/OnClickListener` to be called when the chip is clicked. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setSelected(boolean)(isSelected: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets the selected state of the chip, similar to how toggle has a selected state. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setStartIcon(androidx.car.app.model.CarIcon)(startIcon: https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon)` Sets the icon to display at the start of the chip. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setStyle(androidx.car.app.model.ChipStyle)(style: https://developer.android.com/reference/kotlin/androidx/car/app/model/ChipStyle)` Sets the style of the chip. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setTitle(androidx.car.app.model.CarText)(title: https://developer.android.com/reference/kotlin/androidx/car/app/model/CarText)` Sets the title of the chip, with support for multiple length variants. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setTitle(java.lang.CharSequence)(title: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)` Sets the title of the chip. |

## Public constructors

### Builder

Added in 1.8.0

```
Builder()
```

## Public functions

### build

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.8.0)

```
fun build(): Chip
```

Constructs the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip` defined by this builder.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the chip does not have a title, start icon, or end icon. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the chip does not have an `https://developer.android.com/reference/kotlin/androidx/car/app/model/OnClickListener`. |

### setEndIcon

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.8.0)

```
fun setEndIcon(endIcon: CarIcon): Chip.Builder
```

Sets the icon to display at the end of the chip.

The icon must conform to .

A chip without an endIcon **must** set `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setTitle(java.lang.CharSequence)` OR `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setStartIcon(androidx.car.app.model.CarIcon)` or the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#build()` will throw an exception. Without an endIcon, the host will render the chip with the passed in title and/or startIcon (depending on which has been set).

The icon will attempt to use the most specific tint supplied; this is, it will try to use the first tint found in the following priority: 1. `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconStyle.Builder#setTint(androidx.car.app.model.CarColor)` set in `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon.Builder#setStyle(androidx.car.app.model.CarIconStyle)` for the `startIcon` property 2. `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setStyle(androidx.car.app.model.ChipStyle)``https://developer.android.com/reference/kotlin/androidx/car/app/model/ChipStyle.Builder#setContentColor(androidx.car.app.model.CarColor)` 3. `https://developer.android.com/reference/kotlin/androidx/car/app/model/ChipSection.Builder#setStyle(androidx.car.app.model.ChipStyle)` content color 4. A host supplied color that matches the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setSelected(boolean)` state Note that if the supplied color fails to meet contrast requirements, a host-supplied fallback that matches the selected state will be used.

Rasterized images such as (`https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/IconCompat#TYPE_BITMAP()`) images will not have any tints **unless explicitly supplied through `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconStyle.Builder#setTint(androidx.car.app.model.CarColor)`.**.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `endIcon` is `null` |

### setOnClickListener

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.8.0)

```
fun setOnClickListener(onClickListener: OnClickListener): Chip.Builder
```

Sets the `https://developer.android.com/reference/kotlin/androidx/car/app/model/OnClickListener` to be called when the chip is clicked.

Note that the listener relates to the UI events and will be executed on the main thread using `https://developer.android.com/reference/android/os/Looper.html#getMainLooper()`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `onClickListener` is `null` |

### setSelected

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.8.0)

```
fun setSelected(isSelected: Boolean): Chip.Builder
```

Sets the selected state of the chip, similar to how toggle has a selected state.

If the selected state is not set, the default will be false

If a custom style is provided through `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setStyle(androidx.car.app.model.ChipStyle)`, changing this selected boolean value will not automatically change the color of this chip. The custom style must also be updated to reflect the selected state. See `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setStyle(androidx.car.app.model.ChipStyle)` or `https://developer.android.com/reference/kotlin/androidx/car/app/model/ChipSection.Builder#setStyle(androidx.car.app.model.ChipStyle)` for more details.

### setStartIcon

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.8.0)

```
fun setStartIcon(startIcon: CarIcon): Chip.Builder
```

Sets the icon to display at the start of the chip.

The icon must conform to .

A chip without a startIcon **must** set `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setTitle(java.lang.CharSequence)` OR `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setEndIcon(androidx.car.app.model.CarIcon)` or the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#build()` will throw an exception. Without a startIcon, the host will render the chip with the passed in title and/or endIcon (depending on which has been set).

The icon will attempt to use the most specific tint supplied; this is, it will try to use the first tint found in the following priority: 1. `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconStyle.Builder#setTint(androidx.car.app.model.CarColor)` set in `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon.Builder#setStyle(androidx.car.app.model.CarIconStyle)` for the `startIcon` property 2. `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setStyle(androidx.car.app.model.ChipStyle)``https://developer.android.com/reference/kotlin/androidx/car/app/model/ChipStyle.Builder#setContentColor(androidx.car.app.model.CarColor)` 3. `https://developer.android.com/reference/kotlin/androidx/car/app/model/ChipSection.Builder#setStyle(androidx.car.app.model.ChipStyle)` content color 4. A host supplied color that matches the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setSelected(boolean)` state Note that if the supplied color fails to meet contrast requirements, a host-supplied fallback that matches the selected state will be used.

Rasterized images such as (`https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/IconCompat#TYPE_BITMAP()`) images will not have any tints **unless explicitly supplied through `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconStyle.Builder#setTint(androidx.car.app.model.CarColor)`.**.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `startIcon` is `null` |

### setStyle

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.8.0)

```
fun setStyle(style: ChipStyle): Chip.Builder
```

Sets the style of the chip.

This style overrides the style set in the `https://developer.android.com/reference/kotlin/androidx/car/app/model/ChipSection` if one is provided. Any fields not explicitly set here or in the `https://developer.android.com/reference/kotlin/androidx/car/app/model/ChipSection` will fall back to the host's default colors. If the style is not set or if the colors do not meet the contrast requirements, the host will set the chip styling to defaults based on the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setSelected(boolean)` state.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `style` is `null` |

### setTitle

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.8.0)

```
fun setTitle(title: CarText): Chip.Builder
```

Sets the title of the chip, with support for multiple length variants.

A chip without a title **must** set `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setStartIcon(androidx.car.app.model.CarIcon)` OR `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setEndIcon(androidx.car.app.model.CarIcon)` or the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#build()` will throw an exception. Without a title, the host will render the chip with the passed in startIcon and/or endIcon (depending on which has been set).

The text must conform to .

Developers can provide a shorter `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarText.Builder#addVariant(java.lang.CharSequence)` variant in case their title length exceeds the chip width limit enforced by the host.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `title` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `title` is empty, or if it contains unsupported spans |

### setTitle

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.8.0)

```
fun setTitle(title: CharSequence): Chip.Builder
```

Sets the title of the chip.

A chip without a title **must** set `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setStartIcon(androidx.car.app.model.CarIcon)` OR `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#setEndIcon(androidx.car.app.model.CarIcon)` or the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Chip.Builder#build()` will throw an exception. Without a title, the host will render the chip with the passed in startIcon and/or endIcon (depending on which has been set).

The text must conform to .

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `title` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `title` is empty, or if it contains unsupported spans |