CarColor
@CarProtocol
class CarColor
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 standardCarColor instances (for example, 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 CarColors 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:
<meta-data android:name="androidx.car.app.theme" android:resource="@style/CarAppTheme"/>
CarAppTheme style is defined as any other themes in a resource file:
<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>
createCustom. 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 CarColor |
A standard blue color. |
const CarColor |
Indicates that a default color should be used. |
const CarColor |
A standard green color. |
const CarColor |
Indicates that the app primary color and its dark version should be used, as declared in the app manifest through the |
const CarColor |
A standard red color. |
const CarColor |
Indicates that the app secondary color and its dark version should be used, as declared in the app manifest through the |
const Int |
TYPE_BLUE = 6The standard blue color. |
const Int |
TYPE_CUSTOM = 0A custom, non-standard, app-defined color. |
const Int |
TYPE_DEFAULT = 1A default color, chosen by the host. |
const Int |
TYPE_GREEN = 5The standard green color. |
const Int |
TYPE_PRIMARY = 2The primary app color. |
const Int |
TYPE_RED = 4The standard red color. |
const Int |
TYPE_SECONDARY = 3The secondary app color. |
const Int |
TYPE_YELLOW = 7The standard yellow color. |
const CarColor |
A standard yellow color. |
Public functions |
|
|---|---|
java-static CarColor |
createCustom(color: @ColorInt Int, colorDark: @ColorInt Int)Returns an instance of |
Boolean |
|
@ColorInt Int |
getColor()Returns a packed color int for the light variant of the color, used when the type is |
@ColorInt Int |
Returns a packed color int for the dark variant of the color, used when the type is |
Int |
getType()Returns the type of color for this instance. |
Int |
hashCode() |
String! |
toString() |
Constants
DEFAULT
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.
PRIMARY
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.
SECONDARY
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_CUSTOM
const val TYPE_CUSTOM = 0: Int
A custom, non-standard, app-defined color.
TYPE_DEFAULT
const val TYPE_DEFAULT = 1: Int
A default color, chosen by the host.
| See also | |
|---|---|
DEFAULT |
TYPE_SECONDARY
const val TYPE_SECONDARY = 3: Int
The secondary app color.
| See also | |
|---|---|
SECONDARY |
TYPE_YELLOW
const val TYPE_YELLOW = 7: Int
The standard yellow color.
| See also | |
|---|---|
YELLOW |
Public functions
createCustom
java-static fun createCustom(color: @ColorInt Int, colorDark: @ColorInt Int): CarColor
Returns an instance of CarColor containing a non-standard color.
See the top-level documentation of CarColor for details about how the host determines which variant is used.
getColor
fun getColor(): @ColorInt Int
Returns a packed color int for the light variant of the color, used when the type is TYPE_CUSTOM.
getColorDark
fun getColorDark(): @ColorInt Int
Returns a packed color int for the dark variant of the color, used when the type is TYPE_CUSTOM.