# CarColor

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

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/car/app/model/CarColor "View this page in Java")


```
@CarProtocol
class CarColor
```

<br />

*** ** * ** ***

Represents a color to be used in a car app.

The host chooses the dark or light variant of the color when displaying the user interface, depending where the color is used, to ensure the proper contrast ratio is maintained. For example, the dark variant when may be used as the background of a view with brighter text on it, and the light variant for text on a dark background.

Colors provided by the app should meet the contrast requirements defined by the host, and documented by the app quality guidelines.

#### Standard colors

A set of standard `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor` instances (for example, `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#BLUE()`) is available in this class. It is recommended to use these standard colors whenever possible as they are guaranteed to adhere to the contrast requirements.

#### Primary and secondary colors

The app can define two additional `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor`s in its manifest metadata, through the `
carColorPrimary`, `carColorPrimaryDark`, `
carColorSecondary`, and `carColorSecondaryDark` theme attributes, by declaring them in a theme and referencing the theme from the `
androidx.car.app.theme` metadata. Both the light and dark variants must be declared for the primary and secondary colors, otherwise default variants will be used. Wherever primary and secondary colors are used by the app, the host may use a default color instead if the colors do not pass the contrast requirements.

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="carColorPrimary">@color/my_primary_car_color</item>
    <item name="carColorPrimaryDark">@color/my_primary_dark_car_color</item>
    <item name="carColorSecondary">@color/my_secondary_car_color</item>
    <item name="carColorSecondaryDark">@color/my_secondary_cark_car_color</item>
  </style>
</resources>
```

#### Custom Colors

Besides the primary and secondary colors, custom colors can be created at runtime with `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#createCustom(int,int)`. Wherever custom colors are used by the app, the host may use a default color instead if the custom color does not pass the contrast requirements.

## Summary

| ### Constants |
|---|---|
| `const https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#BLUE()` A standard blue color. |
| `const https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#DEFAULT()` Indicates that a default color should be used. |
| `const https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#GREEN()` A standard green color. |
| `const https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#PRIMARY()` Indicates that the app primary color and its dark version should be used, as declared in the app manifest through the `carColorPrimary` and `carColorPrimaryDark` theme attributes. |
| `const https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#RED()` A standard red color. |
| `const https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#SECONDARY()` Indicates that the app secondary color and its dark version should be used, as declared in the app manifest through the `carColorSecondary` and ` carColorSecondaryDark` theme attributes. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#TYPE_BLUE() = 6` The standard blue color. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#TYPE_CUSTOM() = 0` A custom, non-standard, app-defined color. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#TYPE_DEFAULT() = 1` A default color, chosen by the host. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#TYPE_GREEN() = 5` The standard green color. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#TYPE_PRIMARY() = 2` The primary app color. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#TYPE_RED() = 4` The standard red color. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#TYPE_SECONDARY() = 3` The secondary app color. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#TYPE_YELLOW() = 7` The standard yellow color. |
| `const https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#YELLOW()` A standard yellow color. |

| ### Public functions |
|---|---|
| `java-static https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#createCustom(int,int)(color: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, colorDark: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns an instance of `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor` containing a non-standard color. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#equals(java.lang.Object)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#getColor()()` Returns a packed color int for the light variant of the color, used when the type is `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#TYPE_CUSTOM()`. |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#getColorDark()()` Returns a packed color int for the dark variant of the color, used when the type is `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#TYPE_CUSTOM()`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#getType()()` Returns the type of color for this instance. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#hashCode()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#toString()()` |

## Constants

### BLUE

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

```
const val BLUE: CarColor
```

A standard blue color.

### DEFAULT

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

```
const val DEFAULT: CarColor
```

Indicates that a default color should be used.

This can be used for example to tell the host that the app has no preference for the tint of an icon, and it should use whatever default it finds appropriate.

### GREEN

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

```
const val GREEN: CarColor
```

A standard green color.

### PRIMARY

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

```
const val PRIMARY: CarColor
```

Indicates that the app primary color and its dark version should be used, as declared in the app manifest through the `carColorPrimary` and `carColorPrimaryDark` theme attributes.

### RED

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

```
const val RED: CarColor
```

A standard red color.

### SECONDARY

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

```
const val SECONDARY: CarColor
```

Indicates that the app secondary color and its dark version should be used, as declared in the app manifest through the `carColorSecondary` and `
carColorSecondaryDark` theme attributes.

### TYPE_BLUE

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

```
const val TYPE_BLUE = 6: Int
```

The standard blue color.

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

### TYPE_CUSTOM

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

```
const val TYPE_CUSTOM = 0: Int
```

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

### TYPE_DEFAULT

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

```
const val TYPE_DEFAULT = 1: Int
```

A default color, chosen by the host.

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

### TYPE_GREEN

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

```
const val TYPE_GREEN = 5: Int
```

The standard green color.

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

### TYPE_PRIMARY

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

```
const val TYPE_PRIMARY = 2: Int
```

The primary app color.

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

### TYPE_RED

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

```
const val TYPE_RED = 4: Int
```

The standard red color.

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

### TYPE_SECONDARY

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

```
const val TYPE_SECONDARY = 3: Int
```

The secondary app color.

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

### TYPE_YELLOW

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

```
const val TYPE_YELLOW = 7: Int
```

The standard yellow color.

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

### YELLOW

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

```
const val YELLOW: CarColor
```

A standard yellow color.

## Public functions

### createCustom

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

```
java-static fun createCustom(color: @ColorInt Int, colorDark: @ColorInt Int): CarColor
```

Returns an instance of `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor` containing a non-standard color.

See the top-level documentation of `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor` for details about how the host determines which variant is used.

### equals

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

### getColor

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

```
fun getColor(): @ColorInt Int
```

Returns a packed color int for the light variant of the color, used when the type is `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#TYPE_CUSTOM()`.

### getColorDark

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

```
fun getColorDark(): @ColorInt Int
```

Returns a packed color int for the dark variant of the color, used when the type is `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#TYPE_CUSTOM()`.

### 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 color for this instance.

### hashCode

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

### toString

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