# Chip.Builder

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.Builder) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

*** ** * ** ***


```
public final class Chip.Builder
```

<br />

*** ** * ** ***

Builder class for `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder#Builder(android.content.Context,androidx.wear.protolayout.ModifiersBuilders.Clickable,androidx.wear.protolayout.DeviceParametersBuilders.DeviceParameters)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/ModifiersBuilders.Clickable clickable, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/DeviceParametersBuilders.DeviceParameters deviceParameters )` Creates a builder for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip` with associated action. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Chip` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder#build()()` Constructs and returns `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip` with the provided content and look. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder#setChipColors(androidx.wear.protolayout.material.ChipColors)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/ChipColors chipColors)` Sets the colors for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder#setContentDescription(java.lang.CharSequence)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html contentDescription)` Sets the static content description for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder#setContentDescription(androidx.wear.protolayout.TypeBuilders.StringProp)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/TypeBuilders.StringProp contentDescription )` Sets the content description for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder#setCustomContent(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement content)` Sets the custom content for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder#setHorizontalAlignment(int)(int horizontalAlignment)` Sets the horizontal alignment in the chip. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder#setIconContent(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html imageResourceId)` Sets the icon for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder#setPrimaryLabelContent(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html primaryLabel)` Sets the primary label for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder#setSecondaryLabelContent(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html secondaryLabel)` Sets the secondary label for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder#setWidth(androidx.wear.protolayout.DimensionBuilders.ContainerDimension)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.ContainerDimension width)` Sets the width of `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder#setWidth(float)(@https://developer.android.com/reference/androidx/annotation/Dimension(unit = 0) float width)` Sets the width of `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. |

## Public constructors

### Builder

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

```
public Builder(
    @NonNull Context context,
    @NonNull ModifiersBuilders.Clickable clickable,
    @NonNull DeviceParametersBuilders.DeviceParameters deviceParameters
)
```

Creates a builder for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip` with associated action. It is required to add content later with setters.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | The application's context. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/ModifiersBuilders.Clickable clickable` | Associated `https://developer.android.com/reference/androidx/wear/protolayout/ModifiersBuilders.Clickable` for click events. When the Chip is clicked it will fire the associated action. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/DeviceParametersBuilders.DeviceParameters deviceParameters` | The device parameters used to derive defaults for this Chip. |

## Public methods

### build

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

```
public @NonNull Chip build()
```

Constructs and returns `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip` with the provided content and look.

### setChipColors

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

```
public @NonNull Chip.Builder setChipColors(@NonNull ChipColors chipColors)
```

Sets the colors for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. If set, `https://developer.android.com/reference/androidx/wear/protolayout/material/ChipColors#getBackgroundColor()` will be used for the background of the button, `https://developer.android.com/reference/androidx/wear/protolayout/material/ChipColors#getContentColor()` for main text, `https://developer.android.com/reference/androidx/wear/protolayout/material/ChipColors#getSecondaryContentColor()` for label text and `https://developer.android.com/reference/androidx/wear/protolayout/material/ChipColors#getIconColor()` will be used as color for the icon itself. If not set, `https://developer.android.com/reference/androidx/wear/protolayout/material/ChipDefaults#PRIMARY_COLORS()` will be used.

### setContentDescription

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

```
public @NonNull Chip.Builder setContentDescription(@NonNull CharSequence contentDescription)
```

Sets the static content description for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. It is highly recommended to provide this for chip containing icon.

### setContentDescription

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

```
public @NonNull Chip.Builder setContentDescription(
    @NonNull TypeBuilders.StringProp contentDescription
)
```

Sets the content description for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. It is highly recommended to provide this for chip containing icon.

While this field is statically accessible from 1.0, it's only bindable since version 1.2 and renderers supporting version 1.2 will use the dynamic value (if set).

### setCustomContent

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

```
public @NonNull Chip.Builder setCustomContent(@NonNull LayoutElementBuilders.LayoutElement content)
```

Sets the custom content for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. Any previously added content will be overridden.

### setHorizontalAlignment

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

```
public @NonNull Chip.Builder setHorizontalAlignment(int horizontalAlignment)
```

Sets the horizontal alignment in the chip. It is strongly recommended that the content of the chip is start-aligned if there is more than primary text in it. By default, `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders#HORIZONTAL_ALIGN_CENTER()` will be used when only a primary label is present. Otherwise `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders#HORIZONTAL_ALIGN_START()` will be used.

### setIconContent

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

```
public @NonNull Chip.Builder setIconContent(@NonNull String imageResourceId)
```

Sets the icon for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. Any previously added custom content will be overridden. Provided icon will be tinted to the given content color from `https://developer.android.com/reference/androidx/wear/protolayout/material/ChipColors`. This icon should be image with chosen alpha channel and not an actual image. If icon is set, primary label must be set too with `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder#setPrimaryLabelContent(java.lang.String)`.

### setPrimaryLabelContent

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

```
public @NonNull Chip.Builder setPrimaryLabelContent(@NonNull String primaryLabel)
```

Sets the primary label for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. Any previously added custom content will be overridden. Primary label can be on 1 or 2 lines, depending on the length and existence of secondary label.

### setSecondaryLabelContent

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

```
public @NonNull Chip.Builder setSecondaryLabelContent(@NonNull String secondaryLabel)
```

Sets the secondary label for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. Any previously added custom content will be overridden. If secondary label is set, primary label must be set too with `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip.Builder#setPrimaryLabelContent(java.lang.String)`.

### setWidth

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

```
public @NonNull Chip.Builder setWidth(@NonNull DimensionBuilders.ContainerDimension width)
```

Sets the width of `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. If not set, default value will be set to fill the screen.

### setWidth

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

```
public @NonNull Chip.Builder setWidth(@Dimension(unit = 0) float width)
```

Sets the width of `https://developer.android.com/reference/androidx/wear/protolayout/material/Chip`. If not set, default value will be set to fill the screen.