public final class CarIconSpan
extends CarSpan


A span that replaces the text it is attached to with a CarIcon that is aligned with the surrounding text.

The image may be scaled with the text differently depending on the template that the text belongs to. Refer to the documentation of each template for that information.

For example, the following code creates a string for a navigation maneuver that has an image with the number of a highway rendered as an icon in between "on" and "East":

SpannableString string = new SpannableString("Turn right on 520 East");
     CarIconSpan.create(new CarIcon.Builder(
         IconCompat.createWithResource(getCarContext(), R.drawable.ic_520_highway))),

CarIconSpans in strings passed to the library templates may be ignored by the host when displaying the text unless support for them is explicitly documented in the API that takes the string.

This span will be ignored if it overlaps with any span that replaces text, such as another DistanceSpan, DurationSpan, or CarIconSpan.

See also:




A constant indicating that the bottom of this span should be aligned with the baseline of the surrounding text.


A constant indicating that the bottom of this span should be aligned with the bottom of the surrounding text, at the same level as the lowest descender in the text.


A constant indicating that this span should be vertically centered between the top and the lowest descender.

Public methods

static CarIconSpan create(CarIcon icon)

Creates a CarIconSpan from a CarIcon with a default alignment of ALIGN_BASELINE.

static CarIconSpan create(CarIcon icon, int alignment)

Creates a CarIconSpan from a CarIcon, specifying the alignment of the icon with respect to its surrounding text.

boolean equals(Object other)
int getAlignment()

Returns the alignment that should be used with this span.

CarIcon getIcon()

Returns the CarIcon instance associated with this span.

int hashCode()
String toString()