# 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
class CarIcon
```

<br />

*** ** * ** ***

Represents an icon to be used in a car app.

Car icons wrap a backing `https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/IconCompat`, and add additional attributes optimized for the car such as a `https://developer.android.com/reference/kotlin/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/kotlin/androidx/car/app/CarContext` for more details.

#### Themed Drawables

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

```kotlin
<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:

```kotlin
<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:

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

## Summary

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

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

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

```
const val ALERT: CarIcon
```

An icon representing an alert.

### APP_ICON

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

```
const val APP_ICON: CarIcon
```

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)

```
const val BACK: CarIcon
```

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)
const val COMPOSE_MESSAGE: CarIcon
```

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)

```
const val ERROR: CarIcon
```

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)
const val MEDIA_PLAYBACK: CarIcon
```

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/kotlin/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)
const val PAN: CarIcon
```

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)

```
const val TYPE_ALERT = 4: Int
```

An alert icon.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/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)

```
const val TYPE_APP_ICON = 5: Int
```

The app's icon.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/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)

```
const val TYPE_BACK = 3: Int
```

An icon representing a "back" action.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/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)

```
const val TYPE_COMPOSE_MESSAGE = 8: Int
```

A message icon.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/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)

```
const val TYPE_CUSTOM = 1: Int
```

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)

```
const val TYPE_ERROR = 6: Int
```

An error icon.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/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)

```
const val TYPE_MEDIA_PLAYBACK = 9: Int
```

A media playback icon.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/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)

```
const val TYPE_PAN = 7: Int
```

A pan icon.

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

## Public functions

### createOriginalIcon

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

```
java-static fun createOriginalIcon(icon: IconCompat): CarIcon
```

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

| Parameters |
|---|---|
| `icon: https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/IconCompat` | The base icon graphic. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon` | A styled `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon` instance configured with `https://developer.android.com/reference/kotlin/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)

```
java-static fun createTintedIcon(icon: IconCompat): CarIcon
```

Creates a tinted `https://developer.android.com/reference/kotlin/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/kotlin/androidx/car/app/model/CarIcon#createTintedIcon(androidx.core.graphics.drawable.IconCompat,androidx.car.app.model.CarColor)`.

| Parameters |
|---|---|
| `icon: https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/IconCompat` | The base icon graphic. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon` | A styled `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon` instance configured with `https://developer.android.com/reference/kotlin/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/kotlin/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)

```
java-static fun createTintedIcon(icon: IconCompat, tint: CarColor): CarIcon
```

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

| Parameters |
|---|---|
| `icon: https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/IconCompat` | The base icon graphic. |
| `tint: https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor` | The custom tint color to apply to the icon. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon` | A styled `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon` instance configured with `https://developer.android.com/reference/kotlin/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/kotlin/androidx/car/app/model/CarIcon#createTintedIcon(androidx.core.graphics.drawable.IconCompat)` |   |

### equals

```
fun equals(other: Any?): Boolean
```

### getIcon

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

```
fun getIcon(): IconCompat?
```

Returns the `https://developer.android.com/reference/kotlin/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/kotlin/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)

```
fun getStyle(): CarIconStyle?
```

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

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/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)

```
fun [getTint](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon#getTint())(): CarColor?
```

> [!CAUTION]
> **This function is deprecated.**   
>
> use `https://developer.android.com/reference/kotlin/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/kotlin/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)

```
fun getType(): Int
```

Returns the type of car icon for this instance.

### hashCode

```
fun hashCode(): Int
```

### toString

```
fun toString(): String
```