# Badge.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/Badge.java+class:androidx.car.app.model.Badge.Builder) Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.4.0)

*** ** * ** ***


```
public final class Badge.Builder
```

<br />

*** ** * ** ***

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

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/car/app/model/Badge.Builder#Builder()()` Returns an empty `https://developer.android.com/reference/androidx/car/app/model/Badge.Builder` instance. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Badge` | `https://developer.android.com/reference/androidx/car/app/model/Badge.Builder#build()()` Constructs the `https://developer.android.com/reference/androidx/car/app/model/Badge` defined by this builder. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Badge.Builder` | `[setBackgroundColor](https://developer.android.com/reference/androidx/car/app/model/Badge.Builder#setBackgroundColor(androidx.car.app.model.CarColor))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarColor backgroundColor)` **This method is deprecated.** use `https://developer.android.com/reference/androidx/car/app/model/Badge.Builder#setDotColor(androidx.car.app.model.CarColor)` instead. <br /> |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Badge.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Badge.Builder#setDotColor(androidx.car.app.model.CarColor)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarColor color)` Sets the color of the dot to the given `color`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Badge.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Badge.Builder#setHasDot(boolean)(boolean hasDot)` Enables a circular dot that denotes some sort of alert, notification, etc. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Badge.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Badge.Builder#setIcon(androidx.car.app.model.CarIcon)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon icon)` Sets an icon to be displayed as a badge. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Badge.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Badge.Builder#setIconBackgroundColor(androidx.car.app.model.CarColor)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarColor color)` Sets the color of the icon background to the given `color`. |

## Public constructors

### Builder

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

```
public Builder()
```

Returns an empty `https://developer.android.com/reference/androidx/car/app/model/Badge.Builder` instance.

## Public methods

### build

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

```
public @NonNull Badge build()
```

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

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the badge doesn't have a dot or an icon. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the a dot color is set but the badge has no dot. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the a icon background color is set but the badge has no icon. |

### setBackgroundColor

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

```
public @NonNull Badge.Builder [setBackgroundColor](https://developer.android.com/reference/androidx/car/app/model/Badge.Builder#setBackgroundColor(androidx.car.app.model.CarColor))(@NonNull CarColor backgroundColor)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> use `https://developer.android.com/reference/androidx/car/app/model/Badge.Builder#setDotColor(androidx.car.app.model.CarColor)` instead.

Sets the color of the dot to the given `backgroundColor`.

### setDotColor

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

```
public @NonNull Badge.Builder setDotColor(@NonNull CarColor color)
```

Sets the color of the dot to the given `color`.

### setHasDot

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

```
public @NonNull Badge.Builder setHasDot(boolean hasDot)
```

Enables a circular dot that denotes some sort of alert, notification, etc.

### setIcon

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

```
public @NonNull Badge.Builder setIcon(@NonNull CarIcon icon)
```

Sets an icon to be displayed as a badge.

An icon badge gives context about the associated element on which it is displayed. For example, a work profile icon badge is displayed with an app icon to indicate that it is a work app.

### setIconBackgroundColor

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

```
public @NonNull Badge.Builder setIconBackgroundColor(@NonNull CarColor color)
```

Sets the color of the icon background to the given `color`.