Android 12 Developer Preview is here! Try it out, and give us your feedback!

CarIcon

public class CarIcon
extends Object

java.lang.Object
   ↳ com.google.android.libraries.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 pixel densities. To ensure that icons and images render well across all car screens, use vector assets whenever possible to avoid scaling issues.

In order to support all car screen sizes and pixel density, you can use configuration qualifiers in your resource files (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 com.google.android.libraries.car.app.theme metadata.

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

<meta-data
   android:name="com.google.android.libraries.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

Fields

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 methods

static CarIcon.Builder builder(IconCompat icon)

Returns a CarIcon.Builder instance using the given IconCompat.

boolean equals(Object other)
int hashCode()
CarIcon.Builder newBuilder()

Returns a CarIcon.Builder instance configured with the same data as this CarIcon instance.

static CarIcon of(IconCompat icon)

Returns a CarIcon instance wrapping the given IconCompat.

String toString()

Inherited methods

Fields

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.

Public methods

builder

public static CarIcon.Builder builder (IconCompat icon)

Returns a CarIcon.Builder instance using the given IconCompat.

The following types are supported:

IconCompat.TYPE_URI is only supported in templates that explicitly allow it. In those cases, the appropriate APIs will be documented to indicate this.

For IconCompat.TYPE_URI, the URI's scheme must be ContentResolver.SCHEME_CONTENT.

If the icon image is loaded from URI, it may be cached on the host side. Changing the contents of the URI will result in the host showing a stale image.

Parameters
icon IconCompat

Returns
CarIcon.Builder

Throws
IllegalArgumentException if icon's URI scheme is not supported.
NullPointerException if icon is null.

equals

public boolean equals (Object other)

Parameters
other Object

Returns
boolean

hashCode

public int hashCode ()

Returns
int

newBuilder

public CarIcon.Builder newBuilder ()

Returns a CarIcon.Builder instance configured with the same data as this CarIcon instance.

Returns
CarIcon.Builder

of

public static CarIcon of (IconCompat icon)

Returns a CarIcon instance wrapping the given IconCompat.

Parameters
icon IconCompat

Returns
CarIcon

Throws
IllegalArgumentException if icon's type is not supported.
NullPointerException if icon is null.

toString

public String toString ()

Returns
String