CarIcon

public final class CarIcon
extends Object

java.lang.Object
   ↳ androidx.car.app.model.CarIcon


Represents an icon to be used in a car app.

Car icons wrap a backing IconCompat, and add additional attributes optimized for the car such as a 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 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 classes

class CarIcon.Builder

A builder of CarIcon

Constants

int TYPE_ALERT

An alert icon.

int TYPE_APP_ICON

The app's icon.

int TYPE_BACK

An icon representing a "back" action.

int TYPE_CUSTOM

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

int TYPE_ERROR

An error icon.

int TYPE_PAN

A pan icon.

Fields

public static final CarIcon ALERT

An icon representing an alert.

public static final CarIcon APP_ICON

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

public static final CarIcon BACK

An icon representing a "back" action.

public static final CarIcon ERROR

An icon representing an error.

public static final CarIcon PAN

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

Public methods

boolean equals(Object other)
IconCompat getIcon()

Returns the IconCompat instance backing by this car icon or null if one isn't set.

CarColor getTint()

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

int getType()

Returns the type of car icon for this instance.

int hashCode()
String toString()

Inherited methods

Constants

TYPE_ALERT

public static final int TYPE_ALERT

An alert icon.

See also:

Constant Value: 4 (0x00000004)

TYPE_APP_ICON

public static final int TYPE_APP_ICON

The app's icon.

See also:

Constant Value: 5 (0x00000005)

TYPE_BACK

public static final int TYPE_BACK

An icon representing a "back" action.

See also:

Constant Value: 3 (0x00000003)

TYPE_CUSTOM

public static final int TYPE_CUSTOM

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

Constant Value: 1 (0x00000001)

TYPE_ERROR

public static final int TYPE_ERROR

An error icon.

See also:

Constant Value: 6 (0x00000006)

TYPE_PAN

public static final int TYPE_PAN

A pan icon.

See also:

Constant Value: 7 (0x00000007)

Fields

ALERT

public static final CarIcon ALERT

An icon representing an alert.

APP_ICON

public static final 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

public static final CarIcon BACK

An icon representing a "back" action.

ERROR

public static final CarIcon ERROR

An icon representing an error.

PAN

public static final CarIcon PAN

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

Public methods

equals

public boolean equals (Object other)

Parameters
other Object

Returns
boolean

getIcon

public IconCompat getIcon ()

Returns the