# Header.Builder

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/Header.java+class:androidx.car.app.model.Header.Builder) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.2.0)

*** ** * ** ***


```
class Header.Builder
```

<br />

*** ** * ** ***

A builder of `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder#Builder()()` |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder#addEndHeaderAction(androidx.car.app.model.Action)(headerAction: https://developer.android.com/reference/kotlin/androidx/car/app/model/Action)` Adds an `https://developer.android.com/reference/kotlin/androidx/car/app/model/Action` that will be displayed at the end of a header. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder#build()()` Constructs the component defined by this builder. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder` | `@https://developer.android.com/reference/kotlin/androidx/car/app/annotations/ExperimentalCarApi @https://developer.android.com/reference/kotlin/androidx/car/app/annotations/RequiresCarApi(value = 9) https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder#setBackground(androidx.car.app.model.Background)(background: https://developer.android.com/reference/kotlin/androidx/car/app/model/Background)` Sets the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Background` of the component. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder#setStartHeaderAction(androidx.car.app.model.Action)(headerAction: https://developer.android.com/reference/kotlin/androidx/car/app/model/Action)` Sets the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Action` that will be displayed at the start of a header. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder` | `@https://developer.android.com/reference/kotlin/androidx/car/app/annotations/ExperimentalCarApi @https://developer.android.com/reference/kotlin/androidx/car/app/annotations/RequiresCarApi(value = 9) https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder#setStartHeaderImage(androidx.car.app.model.CarIcon)(startHeaderImage: https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon)` Sets the image that will be displayed at the start of the header after the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder#setStartHeaderAction(androidx.car.app.model.Action)`. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder` | `@https://developer.android.com/reference/kotlin/androidx/car/app/annotations/ExperimentalCarApi @https://developer.android.com/reference/kotlin/androidx/car/app/annotations/RequiresCarApi(value = 9) https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder#setSubtitle(androidx.car.app.model.CarText)(subtitle: https://developer.android.com/reference/kotlin/androidx/car/app/model/CarText)` Sets the subtitle of the component. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder` | `@https://developer.android.com/reference/kotlin/androidx/car/app/annotations/ExperimentalCarApi @https://developer.android.com/reference/kotlin/androidx/car/app/annotations/RequiresCarApi(value = 9) https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder#setSubtitle(java.lang.CharSequence)(subtitle: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)` Sets the subtitle of the component. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder#setTitle(androidx.car.app.model.CarText)(title: https://developer.android.com/reference/kotlin/androidx/car/app/model/CarText)` Sets the title of the component, with support for multiple length variants. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder#setTitle(java.lang.CharSequence)(title: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)` Sets the title of the component. |

## Public constructors

### Builder

Added in 1.2.0

```
Builder()
```

## Public functions

### addEndHeaderAction

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

```
fun addEndHeaderAction(headerAction: Action): Header.Builder
```

Adds an `https://developer.android.com/reference/kotlin/androidx/car/app/model/Action` that will be displayed at the end of a header.

Note: End header action will show up differently inside and outside of map-based templates.

- In a Non-map screen (eg. `https://developer.android.com/reference/kotlin/androidx/car/app/model/MessageTemplate`), actions appear as is, just as the app provides. A background color is allowed on the primary action.
- In a Map-based screen (eg. Setting Header in the ContentTemplate in a `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/MapWithContentTemplate`) only actions with custom icons or standard actions will appear in the Header. The label will be stripped off each action if an app still provides that. Any tint on the icon will be disabled and default to neutral token. The background color on the primary action would also be removed.

### build

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

```
fun build(): Header
```

Constructs the component defined by this builder.

#### Requirements

Either a start header `https://developer.android.com/reference/kotlin/androidx/car/app/model/Action` or title must be set on the component.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if neither a title nor start header `https://developer.android.com/reference/kotlin/androidx/car/app/model/Action` is set |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `https://developer.android.com/reference/kotlin/androidx/car/app/model/Action`s towards the end of the header do not meet the template's requirements |

### setBackground

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

```
@ExperimentalCarApi
@RequiresCarApi(value = 9)
fun setBackground(background: Background): Header.Builder
```

Sets the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Background` of the component.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `background` is null |

### setStartHeaderAction

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

```
fun setStartHeaderAction(headerAction: Action): Header.Builder
```

Sets the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Action` that will be displayed at the start of a header.

By default, a header will not have a start action.

#### Requirements

Only one of `https://developer.android.com/reference/kotlin/androidx/car/app/model/Action#APP_ICON()` or `https://developer.android.com/reference/kotlin/androidx/car/app/model/Action#BACK()` is supported as a start header `https://developer.android.com/reference/kotlin/androidx/car/app/model/Action`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `headerAction` does not meet the requirements |
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `headerAction` is `null` |

### setStartHeaderImage

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

```
@ExperimentalCarApi
@RequiresCarApi(value = 9)
fun setStartHeaderImage(startHeaderImage: CarIcon): Header.Builder
```

Sets the image that will be displayed at the start of the header after the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Header.Builder#setStartHeaderAction(androidx.car.app.model.Action)`.

Only custom `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon`s are supported.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `startHeaderImage` is null |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `startHeaderImage` is not a custom icon |

### setSubtitle

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

```
@ExperimentalCarApi
@RequiresCarApi(value = 9)
fun setSubtitle(subtitle: CarText): Header.Builder
```

Sets the subtitle of the component.

Support colors and icons.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `subtitle` is null |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `subtitle` contains unsupported spans |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarText` |   |

### setSubtitle

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

```
@ExperimentalCarApi
@RequiresCarApi(value = 9)
fun setSubtitle(subtitle: CharSequence): Header.Builder
```

Sets the subtitle of the component.

Support colors and icons.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `subtitle` is null |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `subtitle` contains unsupported spans |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarText` |   |

### setTitle

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

```
fun setTitle(title: CarText): Header.Builder
```

Sets the title of the component, with support for multiple length variants.

Only `https://developer.android.com/reference/kotlin/androidx/car/app/model/DistanceSpan`s and `https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan`s are supported in the input string.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `title` is null |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `title` contains unsupported spans |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarText` |   |

### setTitle

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

```
fun setTitle(title: CharSequence): Header.Builder
```

Sets the title of the component.

Only `https://developer.android.com/reference/kotlin/androidx/car/app/model/DistanceSpan`s and `https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan`s are supported in the input string.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `title` is null |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `title` contains unsupported spans |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarText` |   |