# CarIconSpan

# CarIconSpan

Artifact:[androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app)  
[View Source](https://cs.android.com/search?q=file:androidx/car/app/model/CarIconSpan.java+class:androidx.car.app.model.CarIconSpan)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/car/app/model/CarIconSpan "View this page in Java")

<br />

```
@CarProtocol
class CarIconSpan : CarSpan
```

<br />

|---|---|---|-------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)                                               ||||
| ↳ | [android.text.style.CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html)           |||
|   | ↳ | [androidx.car.app.model.CarSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarSpan)            ||
|   |   | ↳ | [androidx.car.app.model.CarIconSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan) |

*** ** * ** ***

A span that replaces the text it is attached to with a[CarIcon](https://developer.android.com/reference/kotlin/androidx/car/app/model/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":  

```kotlin
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](https://developer.android.com/reference/kotlin/androidx/car/app/model/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](https://developer.android.com/reference/kotlin/androidx/car/app/model/DistanceSpan),[DurationSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan), or[CarIconSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan).  

|                                         See also                                         |
|------------------------------------------------------------------------------------------|---|
| [CarIcon](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon) |   |

## Summary

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [ALIGN_BASELINE](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#ALIGN_BASELINE())` = 1` A constant indicating that the bottom of this span should be aligned with the baseline of the surrounding text.                                                  |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [ALIGN_BOTTOM](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#ALIGN_BOTTOM())` = 0` 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. |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [ALIGN_CENTER](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#ALIGN_CENTER())` = 2` A constant indicating that this span should be vertically centered between the top and the lowest descender.                                                         |

|                                              ### Public functions                                              |
|----------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[CarIconSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan) | [create](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#create(androidx.car.app.model.CarIcon))`(icon: `[CarIcon](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon)`)` Creates a[CarIconSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan)from a[CarIcon](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon)with a default alignment of[ALIGN_BASELINE](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#ALIGN_BASELINE()).                           |
| `java-static `[CarIconSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan) | [create](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#create(androidx.car.app.model.CarIcon,int))`(icon: `[CarIcon](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon)`, alignment: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Creates a[CarIconSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan)from a[CarIcon](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon), specifying the alignment of the icon with respect to its surrounding text. |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                            | [equals](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#equals(java.lang.Object))`(other: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?)`                                                                                                                                                                                                                                                                                                                                                                                                            |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                    | [getAlignment](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#getAlignment())`()` Returns the alignment that should be used with this span.                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| [CarIcon](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon)                       | [getIcon](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#getIcon())`()` Returns the[CarIcon](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon)instance associated with this span.                                                                                                                                                                                                                                                                                                                                                                        |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                    | [hashCode](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#hashCode())`()`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                              | [toString](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#toString())`()`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     ### Inherited functions                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From[androidx.car.app.model.CarSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarSpan) |-------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [updateDrawState](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarSpan#updateDrawState(android.text.TextPaint))`(tp: `[TextPaint](https://developer.android.com/reference/android/text/TextPaint.html)`)` |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| From[android.text.style.CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html) |-------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html)`!`               | [getUnderlying](https://developer.android.com/reference/android/text/style/CharacterStyle.html#getUnderlying())`()`                                                                                                                       | | `abstract `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                          | [updateDrawState](https://developer.android.com/reference/android/text/style/CharacterStyle.html#updateDrawState(android.text.TextPaint))`(p: `[TextPaint](https://developer.android.com/reference/android/text/TextPaint.html)`!)`       | | `java-static `[CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html)`!` | [wrap](https://developer.android.com/reference/android/text/style/CharacterStyle.html#wrap(android.text.style.CharacterStyle))`(cs: `[CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html)`!)` | |

## Constants

### ALIGN_BASELINE

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
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

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
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

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
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

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
java-static fun create(icon: CarIcon): CarIconSpan
```

Creates a[CarIconSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan)from a[CarIcon](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon)with a default alignment of[ALIGN_BASELINE](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#ALIGN_BASELINE()).  

|                                                    Throws                                                     |
|---------------------------------------------------------------------------------------------------------------|------------------|
| [java.lang.NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html) | if`icon`is`null` |

|                                                                See also                                                                |
|----------------------------------------------------------------------------------------------------------------------------------------|---|
| [create](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#create(androidx.car.app.model.CarIcon,int)) |   |

### create

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
java-static fun create(icon: CarIcon, alignment: Int): CarIconSpan
```

Creates a[CarIconSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan)from a[CarIcon](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon), specifying the alignment of the icon with respect to its surrounding text.  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `icon: `[CarIcon](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon) | the[CarIcon](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon)to replace the text with                                                                                                                                                                                                                                                                                                                                                                                            |
| `alignment: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)         | the alignment of the[CarIcon](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon)relative to the text. This should be one of[ALIGN_BASELINE](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#ALIGN_BASELINE()),[ALIGN_BOTTOM](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#ALIGN_BOTTOM())or[ALIGN_CENTER](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#ALIGN_CENTER()) |

|                                                        Throws                                                         |
|-----------------------------------------------------------------------------------------------------------------------|-----------------------------------|
| [java.lang.NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html)         | if`icon`is`null`                  |
| [java.lang.IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | if`alignment`is not a valid value |

|                                                       See also                                                       |
|----------------------------------------------------------------------------------------------------------------------|---|
| [ALIGN_BASELINE](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#ALIGN_BASELINE()) |   |
| [ALIGN_BOTTOM](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#ALIGN_BOTTOM())     |   |
| [ALIGN_CENTER](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan#ALIGN_CENTER())     |   |

### equals

```
fun equals(other: Any?): Boolean
```  

### getAlignment

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
fun getAlignment(): Int
```

Returns the alignment that should be used with this span.  

### getIcon

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
fun getIcon(): CarIcon
```

Returns the[CarIcon](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon)instance associated with this span.  

### hashCode

```
fun hashCode(): Int
```  

### toString

```
fun toString(): String
```