CarIconSpan
public
final
class
CarIconSpan
extends CarSpan
java.lang.Object | |||
↳ | android.text.style.CharacterStyle | ||
↳ | androidx.car.app.model.CarSpan | ||
↳ | androidx.car.app.model.CarIconSpan |
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");
string.setSpan(
CarIconSpan.create(new CarIcon.Builder(
IconCompat.createWithResource(getCarContext(), R.drawable.ic_520_highway))),
14, 17, SPAN_INCLUSIVE_EXCLUSIVE);
CarIconSpan
s 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:
Summary
Constants | |
---|---|
int |
ALIGN_BASELINE
A constant indicating that the bottom of this span should be aligned with the baseline of the surrounding text. |
int |
ALIGN_BOTTOM
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. |
int |
ALIGN_CENTER
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 |
static
CarIconSpan
|
create(CarIcon icon, int alignment)
Creates a |
boolean
|
equals(Object other)
|
int
|
getAlignment()
Returns the alignment that should be used with this span. |
CarIcon
|
getIcon()
Returns the |
int
|
hashCode()
|
String
|
toString()
|
Inherited methods | |
---|---|
Constants
ALIGN_BASELINE
public static final int ALIGN_BASELINE
A constant indicating that the bottom of this span should be aligned with the baseline of the surrounding text.
Constant Value: 1 (0x00000001)
ALIGN_BOTTOM
public static final int ALIGN_BOTTOM
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.
Constant Value: 0 (0x00000000)
ALIGN_CENTER
public static final int ALIGN_CENTER
A constant indicating that this span should be vertically centered between the top and the lowest descender.
Constant Value: 2 (0x00000002)
Public methods
create
public static CarIconSpan create (CarIcon icon)
Creates a CarIconSpan
from a CarIcon
with a default alignment of ALIGN_BASELINE
.
Parameters | |
---|---|
icon |
CarIcon |
Returns | |
---|---|
CarIconSpan |
Throws | |
---|---|
NullPointerException |
if icon is null |
See also:
create
public 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.
Parameters | |
---|---|
icon |
CarIcon : the CarIcon to replace the text with |
alignment |
int : the alignment of the CarIcon relative to the text. This should be
one of ALIGN_BASELINE , ALIGN_BOTTOM or
ALIGN_CENTER |
Returns | |
---|---|
CarIconSpan |
Throws | |
---|---|
NullPointerException |
if icon is null |
IllegalArgumentException |
if alignment is not a valid value |
See also:
equals
public boolean equals (Object other)
Parameters | |
---|---|
other |
Object |
Returns | |
---|---|
boolean |
getAlignment
public int getAlignment ()
Returns the alignment that should be used with this span.
Returns | |
---|---|
int |
getIcon
public CarIcon getIcon ()
Returns the CarIcon
instance associated with this span.
Returns | |
---|---|
CarIcon |
hashCode
public int hashCode ()
Returns | |
---|---|
int |
toString
public String toString ()
Returns | |
---|---|
String |