# CarIcon

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

*** ** * ** ***


```
@CarProtocol
public final class CarIcon
```

<br />

*** ** * ** ***

Represents an icon to be used in a car app.

Car icons wrap a backing `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat`, and add additional attributes optimized for the car such as a `https://developer.android.com/reference/androidx/car/app/model/CarColor` tint.

#### Car Screen Pixel Densities

Similar to Android devices, car screens cover a wide range of sizes and densities. To ensure that icons and images render well across all car screens, use vector assets whenever possible to avoid scaling issues. If your app relies on bitmaps or other non-vector assets, you should ensure that you have resources that address multiple pixel density buckets using configuration qualifiers in your resource folders (e.g. "mdpi", "hdpi", etc). See `https://developer.android.com/reference/androidx/car/app/CarContext` for more details.

#### Themed Drawables

Vector drawables can contain references to attributes declared in a theme. For example:

```
<vector ...
  <path
    android:pathData="..."
    android:fillColor="?myIconColor"/>
</vector>
```
The theme must be defined in the app's manifest metadata, by declaring them in a theme and referencing it from the `androidx.car.app.theme` metadata.

In `AndroidManifest.xml`, under the `application` element corresponding to the car app:

```
<meta-data
  android:name="androidx.car.app.theme"
  android:resource="@style/CarAppTheme"/>
```
The `CarAppTheme` style is defined as any other themes in a resource file:

```
<resources>
  <style name="CarAppTheme">
    <item name="myIconColor">@color/my_icon_color</item>
    ...
  </style>
</resources>
```

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder` A builder of `https://developer.android.com/reference/androidx/car/app/model/CarIcon`. |

| ### Constants |
|---|---|
| `static final @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#ALERT()` An icon representing an alert. |
| `static final @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#APP_ICON()` Represents the app's icon, as defined in the app's manifest by the `android:icon` attribute of the `application` element. |
| `static final @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#BACK()` An icon representing a "back" action. |
| `static final @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/annotations/RequiresCarApi(value = 7) https://developer.android.com/reference/androidx/car/app/model/CarIcon#COMPOSE_MESSAGE()` An icon that represents the user's intent to send a message. |
| `static final @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#ERROR()` An icon representing an error. |
| `static final @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/annotations/RequiresCarApi(value = 8) https://developer.android.com/reference/androidx/car/app/model/CarIcon#MEDIA_PLAYBACK()` An icon that represents a playable media item. |
| `static final @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/annotations/RequiresCarApi(value = 2) https://developer.android.com/reference/androidx/car/app/model/CarIcon#PAN()` An icon representing a pan action (for example, in a map surface). |
| `static final int` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon#TYPE_ALERT() = 4` An alert icon. |
| `static final int` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon#TYPE_APP_ICON() = 5` The app's icon. |
| `static final int` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon#TYPE_BACK() = 3` An icon representing a "back" action. |
| `static final int` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon#TYPE_COMPOSE_MESSAGE() = 8` A message icon. |
| `static final int` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon#TYPE_CUSTOM() = 1` A custom, non-standard, app-defined icon. |
| `static final int` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon#TYPE_ERROR() = 6` An error icon. |
| `static final int` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon#TYPE_MEDIA_PLAYBACK() = 9` A media playback icon. |
| `static final int` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon#TYPE_PAN() = 7` A pan icon. |

| ### Public methods |
|---|---|
| `static @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#createOriginalIcon(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 an icon that retains its original colors without allowing any host-side tinting on it. |
| `static @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#createTintedIcon(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 tinted `https://developer.android.com/reference/androidx/car/app/model/CarIcon`. |
| `static @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#createTintedIcon(androidx.core.graphics.drawable.IconCompat,androidx.car.app.model.CarColor)(@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/CarColor tint)` Creates a tinted `https://developer.android.com/reference/androidx/car/app/model/CarIcon` with the given `https://developer.android.com/reference/androidx/car/app/model/CarColor` tint. |
| `boolean` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon#equals(java.lang.Object)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html other)` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon#getIcon()()` Returns the `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat` instance backing by this car icon or `null` if one isn't set. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/CarIconStyle` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon#getStyle()()` Returns the style of the icon or `null` if not set. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/CarColor` | `[getTint](https://developer.android.com/reference/androidx/car/app/model/CarIcon#getTint())()` **This method is deprecated.** use `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle#getTint()` instead <br /> |
| `int` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon#getType()()` Returns the type of car icon for this instance. |
| `int` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon#hashCode()()` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/car/app/model/CarIcon#toString()()` |

## Constants

### ALERT

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

```
public static final @NonNull CarIcon ALERT
```

An icon representing an alert.

### APP_ICON

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

```
public static final @NonNull CarIcon APP_ICON
```

Represents the app's icon, as defined in the app's manifest by the `android:icon` attribute of the `application` element.

### BACK

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

```
public static final @NonNull CarIcon BACK
```

An icon representing a "back" action.

### COMPOSE_MESSAGE

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

```
@RequiresCarApi(value = 7)
public static final @NonNull CarIcon COMPOSE_MESSAGE
```

An icon that represents the user's intent to send a message.

### ERROR

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

```
public static final @NonNull CarIcon ERROR
```

An icon representing an error.

### MEDIA_PLAYBACK

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

```
@RequiresCarApi(value = 8)
public static final @NonNull CarIcon MEDIA_PLAYBACK
```

An icon that represents a playable media item. Note: This is specifically used for category MEDIA apps. Used in conjunction with `https://developer.android.com/reference/androidx/car/app/model/Action#MEDIA_PLAYBACK()`

### PAN

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

```
@RequiresCarApi(value = 2)
public static final @NonNull CarIcon PAN
```

An icon representing a pan action (for example, in a map surface).

### TYPE_ALERT

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

```
public static final int TYPE_ALERT = 4
```

An alert icon.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarIcon#ALERT()` |   |

### TYPE_APP_ICON

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

```
public static final int TYPE_APP_ICON = 5
```

The app's icon.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarIcon#APP_ICON()` |   |

### TYPE_BACK

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

```
public static final int TYPE_BACK = 3
```

An icon representing a "back" action.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarIcon#BACK()` |   |

### TYPE_COMPOSE_MESSAGE

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

```
public static final int TYPE_COMPOSE_MESSAGE = 8
```

A message icon.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarIcon#COMPOSE_MESSAGE()` |   |

### TYPE_CUSTOM

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

```
public static final int TYPE_CUSTOM = 1
```

A custom, non-standard, app-defined icon.

### TYPE_ERROR

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

```
public static final int TYPE_ERROR = 6
```

An error icon.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarIcon#ERROR()` |   |

### TYPE_MEDIA_PLAYBACK

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

```
public static final int TYPE_MEDIA_PLAYBACK = 9
```

A media playback icon.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarIcon#MEDIA_PLAYBACK()` |   |

### TYPE_PAN

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

```
public static final int TYPE_PAN = 7
```

A pan icon.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarIcon#PAN()` |   |

## Public methods

### createOriginalIcon

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

```
public static @NonNull CarIcon createOriginalIcon(@NonNull IconCompat icon)
```

Creates an icon that retains its original colors without allowing any host-side tinting on it.

| 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 graphic. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon` | A styled `https://developer.android.com/reference/androidx/car/app/model/CarIcon` instance configured with `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle#ORIGINAL()`. |

### createTintedIcon

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

```
public static @NonNull CarIcon createTintedIcon(@NonNull IconCompat icon)
```

Creates a tinted `https://developer.android.com/reference/androidx/car/app/model/CarIcon`.

By default, using this method allows the host vehicle system to automatically tint the icon based on the active template theme. To apply a custom tint instead, use `https://developer.android.com/reference/androidx/car/app/model/CarIcon#createTintedIcon(androidx.core.graphics.drawable.IconCompat,androidx.car.app.model.CarColor)`.

| 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 graphic. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon` | A styled `https://developer.android.com/reference/androidx/car/app/model/CarIcon` instance configured with `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle#TINTED()`. |

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarIcon#createTintedIcon(androidx.core.graphics.drawable.IconCompat,androidx.car.app.model.CarColor)` |   |

### createTintedIcon

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

```
public static @NonNull CarIcon createTintedIcon(@NonNull IconCompat icon, @NonNull CarColor tint)
```

Creates a tinted `https://developer.android.com/reference/androidx/car/app/model/CarIcon` with the given `https://developer.android.com/reference/androidx/car/app/model/CarColor` tint.

| 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 graphic. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarColor tint` | The custom tint color to apply to the icon. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon` | A styled `https://developer.android.com/reference/androidx/car/app/model/CarIcon` instance configured with `https://developer.android.com/reference/androidx/car/app/model/CarIconStyle#TINTED()` and the specified tint. |

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarIcon#createTintedIcon(androidx.core.graphics.drawable.IconCompat)` |   |

### equals

```
public boolean equals(@Nullable Object other)
```

### getIcon

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

```
public @Nullable IconCompat getIcon()
```

Returns the `https://developer.android.com/reference/androidx/core/graphics/drawable/IconCompat` instance backing by this car icon or `null` if one isn't set.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder#Builder(androidx.core.graphics.drawable.IconCompat)` |   |

### getStyle

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

```
public @Nullable CarIconStyle getStyle()
```

Returns the style of the icon or `null` if not set.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder#setStyle(androidx.car.app.model.CarIconStyle)` |   |

### getTint

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 @Nullable CarColor [getTint](https://developer.android.com/reference/androidx/car/app/model/CarIcon#getTint())()
```

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

Returns the tint of the icon or `null` if not set.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarIcon.Builder#setTint(androidx.car.app.model.CarColor)` |   |

### getType

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

```
public int getType()
```

Returns the type of car icon for this instance.

### hashCode

```
public int hashCode()
```

### toString

```
public @NonNull String toString()
```