# 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)

*** ** * ** ***


```
@CarProtocol
public final class ForegroundCarColorSpan extends CarSpan
```

<br />

|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.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/androidx/car/app/model/CarSpan) ||
|   |   | ↳ | [androidx.car.app.model.ForegroundCarColorSpan](https://developer.android.com/reference/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:

```
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 `https://developer.android.com/reference/androidx/car/app/model/ForegroundCarColorSpan` and instead use a default color unless support for `https://developer.android.com/reference/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 |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarColor` |   |
| `https://developer.android.com/reference/android/text/style/ForegroundColorSpan.html` |   |

## Summary

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/ForegroundCarColorSpan` | `https://developer.android.com/reference/androidx/car/app/model/ForegroundCarColorSpan#create(androidx.car.app.model.CarColor)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarColor carColor)` Creates a `https://developer.android.com/reference/android/text/style/ForegroundColorSpan.html` from a `https://developer.android.com/reference/androidx/car/app/model/CarColor`. |
| `boolean` | `https://developer.android.com/reference/androidx/car/app/model/ForegroundCarColorSpan#equals(java.lang.Object)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html other)` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarColor` | `https://developer.android.com/reference/androidx/car/app/model/ForegroundCarColorSpan#getColor()()` Returns the `https://developer.android.com/reference/androidx/car/app/model/CarColor` associated with this span. |
| `int` | `https://developer.android.com/reference/androidx/car/app/model/ForegroundCarColorSpan#hashCode()()` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/car/app/model/ForegroundCarColorSpan#toString()()` |

| ### Inherited methods |
|---|
| From [androidx.car.app.model.CarSpan](https://developer.android.com/reference/androidx/car/app/model/CarSpan) |---|---| | `void` | `https://developer.android.com/reference/androidx/car/app/model/CarSpan#updateDrawState(android.text.TextPaint)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/text/TextPaint.html tp)` | |
| From [android.text.style.CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html) |---|---| | `https://developer.android.com/reference/android/text/style/CharacterStyle.html` | `https://developer.android.com/reference/android/text/style/CharacterStyle.html#getUnderlying()()` | | `abstract void` | `https://developer.android.com/reference/android/text/style/CharacterStyle.html#updateDrawState(android.text.TextPaint)(https://developer.android.com/reference/android/text/TextPaint.html p)` | | `static https://developer.android.com/reference/android/text/style/CharacterStyle.html` | `https://developer.android.com/reference/android/text/style/CharacterStyle.html#wrap(android.text.style.CharacterStyle)(https://developer.android.com/reference/android/text/style/CharacterStyle.html cs)` | |

## Public methods

### create

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

```
public static @NonNull ForegroundCarColorSpan create(@NonNull CarColor carColor)
```

Creates a `https://developer.android.com/reference/android/text/style/ForegroundColorSpan.html` from a `https://developer.android.com/reference/androidx/car/app/model/CarColor`.

Custom colors created with `https://developer.android.com/reference/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 |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `carColor` contains a custom color |
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `carColor` is `null` |

### equals

```
public boolean equals(@Nullable Object other)
```

### getColor

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

```
public @NonNull CarColor getColor()
```

Returns the `https://developer.android.com/reference/androidx/car/app/model/CarColor` associated with this span.

### hashCode

```
public int hashCode()
```

### toString

```
public @NonNull String toString()
```