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

*** ** * ** ***


```
public final class CarIcon.Builder
```

<br />

*** ** * ** ***

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

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder#Builder(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 carIcon)` Returns a `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder` instance configured with the same data as the given `https://developer.android.com/reference/androidx/car/app/model/CarIcon` instance. |
| `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder#Builder(androidx.core.graphics.drawable.IconCompat)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat icon)` Creates a `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder` instance using the given `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat`. |
| `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder#Builder(androidx.core.graphics.drawable.IconCompat,androidx.car.app.model.CarIconStyle)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat icon, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIconStyle style)` Creates a `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder` instance using the given `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat` and explicit `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle`. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder#build()()` Constructs the `https://developer.android.com/reference/androidx/car/app/model/CarIcon` defined by this builder. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder#setStyle(androidx.car.app.model.CarIconStyle)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIconStyle style)` Sets the style of the icon to the given `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder` | `[setTint](https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder#setTint(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 tint)` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder#setStyle(androidx.car.app.model.CarIconStyle)` and provide a tint via `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle.Builder#setTint(androidx.car.app.model.CarColor)`, or use `https://developer.android.com/reference/androidx/car/app/model/CarIcon#createTintedIcon(androidx.core.graphics.drawable.IconCompat,androidx.car.app.model.CarColor)` instead. <br /> |

## Public constructors

### Builder

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

```
public Builder(@NonNull CarIcon carIcon)
```

Returns a `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder` instance configured with the same data as the given `https://developer.android.com/reference/androidx/car/app/model/CarIcon` instance.

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

### Builder

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

```
public Builder(@NonNull IconCompat icon)
```

Creates a `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder` instance using the given `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat`.

The following types are supported:

- `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat#TYPE_BITMAP()`
- `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat#TYPE_RESOURCE()`
- `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat#TYPE_URI()`

`https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat#TYPE_URI()` is only supported in templates that explicitly allow it. In those cases, the appropriate APIs will be documented to indicate this.

For `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat#TYPE_URI()`, the URI's scheme must be `https://developer.android.com/reference/android/content/ContentResolver.html#SCHEME_CONTENT`.

If the icon image is loaded from URI, it may be cached on the host side. Changing the contents of the URI will result in the host showing a stale image.

**Note:** It is recommended to use `https://developer.android.com/reference/androidx/car/app/model/CarIcon#createTintedIcon(androidx.core.graphics.drawable.IconCompat)`, `https://developer.android.com/reference/androidx/car/app/model/CarIcon#createTintedIcon(androidx.core.graphics.drawable.IconCompat,androidx.car.app.model.CarColor)`, `https://developer.android.com/reference/androidx/car/app/model/CarIcon#createOriginalIcon(androidx.core.graphics.drawable.IconCompat)`, or `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder#Builder(androidx.core.graphics.drawable.IconCompat,androidx.car.app.model.CarIconStyle)` to explicitly specify visual styling behavior. This constructor will be deprecated in a future release.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `icon`'s URI scheme is not supported |
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `icon` is `null` |

### Builder

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

```
public Builder(@NonNull IconCompat icon, @NonNull CarIconStyle style)
```

Creates a `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder` instance using the given `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat` and explicit `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle`.

The following types are supported:

- `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat#TYPE_BITMAP()`
- `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat#TYPE_RESOURCE()`
- `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat#TYPE_URI()`

`https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat#TYPE_URI()` is only supported in templates that explicitly allow it. In those cases, the appropriate APIs will be documented to indicate this.

For `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat#TYPE_URI()`, the URI's scheme must be `https://developer.android.com/reference/android/content/ContentResolver.html#SCHEME_CONTENT`.

If the icon image is loaded from URI, it may be cached on the host side. Changing the contents of the URI will result in the host showing a stale image.

Select the appropriate style depending on the asset:

- Use `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle#TINTED()` for icons that should be automatically tinted by the vehicle theme or assigned a custom tint via `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle.Builder#setTint(androidx.car.app.model.CarColor)`.
- Use `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle#ORIGINAL()` for icons that must retain their original colors without host-side tinting (e.g., user avatars, media album art, photos, or un-tinted logos).

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat icon` | The base icon or image graphic. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIconStyle style` | The explicit style contract dictating tinting behavior and optional geometric shaping. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `icon`'s URI scheme is not supported |
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `icon` or `style` is `null` |

## Public methods

### build

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

```
public @NonNull CarIcon build()
```

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

### setStyle

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

```
public @NonNull CarIcon.Builder setStyle(@NonNull CarIconStyle style)
```

Sets the style of the icon to the given `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle`.

Select the appropriate style depending on the asset:

- Use `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle#TINTED()` for icons that should be automatically tinted by the vehicle theme or assigned a custom tint via `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle.Builder#setTint(androidx.car.app.model.CarColor)`.
- Use `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle#ORIGINAL()` for icons that must retain their original colors without host-side tinting (e.g., user avatars, media album art, photos, or un-tinted logos).

If no style is set, an icon using `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle#ORIGINAL()` (with no tint and default shape) will be rendered.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIconStyle style` | The explicit style contract dictating tinting behavior and optional geometric shaping. |

### setTint

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

```
public @NonNull CarIcon.Builder [setTint](https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder#setTint(androidx.car.app.model.CarColor))(@NonNull CarColor tint)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder#setStyle(androidx.car.app.model.CarIconStyle)` and provide a tint via `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle.Builder#setTint(androidx.car.app.model.CarColor)`, or use `https://developer.android.com/reference/androidx/car/app/model/CarIcon#createTintedIcon(androidx.core.graphics.drawable.IconCompat,androidx.car.app.model.CarColor)` instead.

Sets the tint of the icon to the given `https://developer.android.com/reference/androidx/car/app/model/CarColor`.

This tint overrides the tint set through `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat#setTint(int)` in the backing `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat` with a `https://developer.android.com/reference/androidx/car/app/model/CarColor` tint. The tint set through `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat#setTint(int)` is not guaranteed to be applied if the `https://developer.android.com/reference/androidx/car/app/model/CarIcon` tint is not set.

The tint mode used to blend this color is `https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html#SRC_IN`.

Depending on contrast requirements, capabilities of the vehicle screens, or other factors, the color may be ignored by the host or overridden by the vehicle system.

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarColor` |   |
| `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setTintMode(android.graphics.PorterDuff.Mode)` |   |