# ForegroundCarColorSpan

# ForegroundCarColorSpan

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/ForegroundCarColorSpan.java+class:androidx.car.app.model.ForegroundCarColorSpan)  
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/ForegroundCarColorSpan "View this page in Java")

<br />

```
@CarProtocol
class ForegroundCarColorSpan : 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.ForegroundCarColorSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/ForegroundCarColorSpan) |

*** ** * ** ***

A span that changes the color of the text to which the span is attached.

For example, to set a green text color to a span of a string:  

```kotlin
SpannableString string = new SpannableString("Text with a foreground color span");
string.setSpan(ForegroundCarColorSpan.create(CarColor.GREEN),
    12, 28, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE));
```

The host may ignore the color specified in the[ForegroundCarColorSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/ForegroundCarColorSpan)and instead use a default color unless support for[ForegroundCarColorSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/ForegroundCarColorSpan)is explicitly documented in the API that takes the string. Depending on contrast requirements, capabilities of the vehicle screens, or other factors, the color may also be ignored by the host or overridden by the vehicle system.  

|                                                  See also                                                  |
|------------------------------------------------------------------------------------------------------------|---|
| [CarColor](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor)                 |   |
| [ForegroundColorSpan](https://developer.android.com/reference/android/text/style/ForegroundColorSpan.html) |   |

## Summary

|                                                         ### Public functions                                                         |
|--------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[ForegroundCarColorSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/ForegroundCarColorSpan) | [create](https://developer.android.com/reference/kotlin/androidx/car/app/model/ForegroundCarColorSpan#create(androidx.car.app.model.CarColor))`(carColor: `[CarColor](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor)`)` Creates a[ForegroundColorSpan](https://developer.android.com/reference/android/text/style/ForegroundColorSpan.html)from a[CarColor](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor). |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                  | [equals](https://developer.android.com/reference/kotlin/androidx/car/app/model/ForegroundCarColorSpan#equals(java.lang.Object))`(other: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?)`                                                                                                                                                                                                                                                      |
| [CarColor](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor)                                           | [getColor](https://developer.android.com/reference/kotlin/androidx/car/app/model/ForegroundCarColorSpan#getColor())`()` Returns the[CarColor](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor)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/ForegroundCarColorSpan#hashCode())`()`                                                                                                                                                                                                                                                                                                                                                       |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                                    | [toString](https://developer.android.com/reference/kotlin/androidx/car/app/model/ForegroundCarColorSpan#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)`!)` | |

## Public functions

### create

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

```
java-static fun create(carColor: CarColor): ForegroundCarColorSpan
```

Creates a[ForegroundColorSpan](https://developer.android.com/reference/android/text/style/ForegroundColorSpan.html)from a[CarColor](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor).

Custom colors created with[createCustom](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarColor#createCustom(int,int))are not supported in text spans unless explicitly documented otherwise in the API that takes the string.  

|                                                        Throws                                                         |
|-----------------------------------------------------------------------------------------------------------------------|-------------------------------------|
| [java.lang.IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | if`carColor`contains a custom color |
| [java.lang.NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html)         | if`carColor`is`null`                |

### equals

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

### getColor

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

```
fun getColor(): CarColor
```

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

### hashCode

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

### toString

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