CarIconSpan
@CarProtocol
class CarIconSpan : CarSpan
| kotlin.Any | |||
| ↳ | 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);
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 | |
|---|---|
CarIcon |
Summary
Constants |
|
|---|---|
const Int |
ALIGN_BASELINE = 1A constant indicating that the bottom of this span should be aligned with the baseline of the surrounding text. |
const Int |
ALIGN_BOTTOM = 0A 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. |
const Int |
ALIGN_CENTER = 2A constant indicating that this span should be vertically centered between the top and the lowest descender. |
Public functions |
|
|---|---|
java-static CarIconSpan |
Creates a |
java-static CarIconSpan |
Creates a |
Boolean |
|
Int |
Returns the alignment that should be used with this span. |
CarIcon |
getIcon()Returns the |
Int |
hashCode() |
String |
toString() |
Inherited functions |
||||||
|---|---|---|---|---|---|---|
|
||||||
|
Constants
ALIGN_BASELINE
const val ALIGN_BASELINE = 1: Int
A constant indicating that the bottom of this span should be aligned with the baseline of the surrounding text.
ALIGN_BOTTOM
const val ALIGN_BOTTOM = 0: Int
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.
ALIGN_CENTER
const val ALIGN_CENTER = 2: Int
A constant indicating that this span should be vertically centered between the top and the lowest descender.
Public functions
create
java-static fun create(icon: CarIcon): CarIconSpan
Creates a CarIconSpan from a CarIcon with a default alignment of ALIGN_BASELINE.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
| See also | |
|---|---|
create |
create
java-static fun create(icon: CarIcon, alignment: Int): CarIconSpan
Creates a CarIconSpan from a CarIcon, specifying the alignment of the icon with respect to its surrounding text.
| Parameters | |
|---|---|
icon: CarIcon |
the |
alignment: Int |
the alignment of the |
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
java.lang.IllegalArgumentException |
if |
| See also | |
|---|---|
ALIGN_BASELINE |
|
ALIGN_BOTTOM |
|
ALIGN_CENTER |
getAlignment
fun getAlignment(): Int
Returns the alignment that should be used with this span.