CarIcon


@CarProtocol
public final class 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 androidx.car.app.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 types

public final class CarIcon.Builder

A builder of CarIcon.

Constants

static final @NonNull CarIcon

An icon representing an alert.

static final @NonNull CarIcon

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

static final @NonNull CarIcon

An icon representing a "back" action.

static final @NonNull CarIcon

An icon that represents the user's intent to send a message.

static final @NonNull CarIcon

An icon representing an error.

static final @NonNull CarIcon
@RequiresCarApi(value = 2)
PAN

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

static final int

An alert icon.

static final int

The app's icon.

static final int

An icon representing a "back" action.

static final int

A message icon.

static final int

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

static final int

An error icon.

static final int

A pan icon.

Public methods

boolean
@Nullable IconCompat

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

@Nullable CarColor

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

int

Returns the type of car icon for this instance.

int
String

Constants

ALERT

Added in 1.0.0
public static final @NonNull CarIcon ALERT

An icon representing an alert.

APP_ICON

Added in 1.0.0
public static final @NonNull 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

Added in 1.0.0
public static final @NonNull CarIcon BACK

An icon representing a "back" action.

COMPOSE_MESSAGE

Added in 1.4.0
@RequiresCarApi(value = 7)
public static final @NonNull CarIcon COMPOSE_MESSAGE

An icon that represents the user's intent to send a message.

ERROR

Added in 1.0.0
public static final @NonNull CarIcon ERROR

An icon representing an error.

PAN

Added in 1.1.0
@RequiresCarApi(value = 2)
public static final @NonNull CarIcon PAN

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

TYPE_ALERT

Added in 1.0.0
public static final int TYPE_ALERT = 4

An alert icon.

See also
ALERT

TYPE_APP_ICON

Added in 1.0.0
public static final int TYPE_APP_ICON = 5

The app's icon.

See also
APP_ICON

TYPE_BACK

Added in 1.0.0
public static final int TYPE_BACK = 3

An icon representing a "back" action.

See also
BACK

TYPE_COMPOSE_MESSAGE

Added in 1.4.0
public static final int TYPE_COMPOSE_MESSAGE = 8

A message icon.

See also
COMPOSE_MESSAGE

TYPE_CUSTOM

Added in 1.0.0
public static final int TYPE_CUSTOM = 1

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

TYPE_ERROR

Added in 1.0.0
public static final int TYPE_ERROR = 6

An error icon.

See also
ERROR

TYPE_PAN

Added in 1.1.0
public static final int TYPE_PAN = 7

A pan icon.

See also
PAN

Public methods

equals

public boolean equals(@Nullable Object other)

getIcon

Added in 1.0.0
public @Nullable IconCompat getIcon()

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

See also
Builder

getTint

Added in 1.0.0
public @Nullable CarColor getTint()

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

See also
setTint

getType

Added in 1.0.0
public int getType()

Returns the type of car icon for this instance.

hashCode

public int hashCode()

toString

public String toString()