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

*** ** * ** ***


```
@RequiresCarApi(value = 9)
@ExperimentalCarApi
public final class Banner.Builder
```

<br />

*** ** * ** ***

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

## Summary

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

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Banner.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Banner.Builder#addBelowAction(androidx.car.app.model.Action)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Action action)` Adds an `https://developer.android.com/reference/androidx/car/app/model/Action` below the title and subtitle of the `https://developer.android.com/reference/androidx/car/app/model/Banner`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Banner.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Banner.Builder#addTrailingAction(androidx.car.app.model.Action)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Action action)` Adds an `https://developer.android.com/reference/androidx/car/app/model/Action` to the trailing part of the banner. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Banner.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Banner.Builder#addTrailingImage(androidx.car.app.model.CarIcon)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon image)` Adds a `https://developer.android.com/reference/androidx/car/app/model/CarIcon` to be displayed as an `https://developer.android.com/reference/androidx/car/app/model/Banner#IMAGE_TYPE_MEDIUM()` image at the trailing part of the Banner, not expected to be tinted. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Banner.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Banner.Builder#addTrailingImage(androidx.car.app.model.CarIcon,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon image, int imageType)` Adds a `https://developer.android.com/reference/androidx/car/app/model/CarIcon` to be displayed as an image to the trailing part of the banner. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Banner` | `https://developer.android.com/reference/androidx/car/app/model/Banner.Builder#build()()` Constructs the `https://developer.android.com/reference/androidx/car/app/model/Banner` defined by this builder. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Banner.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Banner.Builder#setLeadingImage(androidx.car.app.model.CarIcon)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon image)` Sets the leading element in this banner to be a `https://developer.android.com/reference/androidx/car/app/model/CarIcon` displayed as an `https://developer.android.com/reference/androidx/car/app/model/Banner#IMAGE_TYPE_MEDIUM()` image, not expected to be tinted. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Banner.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Banner.Builder#setLeadingImage(androidx.car.app.model.CarIcon,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon image, int imageType)` Sets the leading element in this banner to be a `https://developer.android.com/reference/androidx/car/app/model/CarIcon` displayed as an image. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Banner.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Banner.Builder#setOnClickListener(androidx.car.app.model.OnClickListener)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/OnClickListener onClickListener)` Sets the `https://developer.android.com/reference/androidx/car/app/model/OnClickListener` to be called back when the banner is clicked. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Banner.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Banner.Builder#setStyle(androidx.car.app.model.BannerStyle)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/BannerStyle style)` Sets the `https://developer.android.com/reference/androidx/car/app/model/BannerStyle` of the banner. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Banner.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Banner.Builder#setSubtitle(androidx.car.app.model.CarText)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarText subtitle)` Sets the subtitle of the banner. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Banner.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Banner.Builder#setSubtitle(java.lang.CharSequence)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html subtitle)` Sets the subtitle of the banner. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Banner.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Banner.Builder#setTitle(androidx.car.app.model.CarText)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarText title)` Sets the title of the banner. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Banner.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Banner.Builder#setTitle(java.lang.CharSequence)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html title)` Sets the title of the banner. |

## Public constructors

### Builder

Added in 1.9.0-alpha03

```
public Builder()
```

## Public methods

### addBelowAction

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

```
public @NonNull Banner.Builder addBelowAction(@NonNull Action action)
```

Adds an `https://developer.android.com/reference/androidx/car/app/model/Action` below the title and subtitle of the `https://developer.android.com/reference/androidx/car/app/model/Banner`.

A `https://developer.android.com/reference/androidx/car/app/model/Banner`'s below actions must conform to .

Below actions cannot be used in combination with a large image.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `action` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `action` does not conform to |

### addTrailingAction

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

```
public @NonNull Banner.Builder addTrailingAction(@NonNull Action action)
```

Adds an `https://developer.android.com/reference/androidx/car/app/model/Action` to the trailing part of the banner.

A banner can have at most 2 trailing elements.

`action` must conform to .

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `action` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if there are already 2 trailing elements |

### addTrailingImage

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

```
public @NonNull Banner.Builder addTrailingImage(@NonNull CarIcon image)
```

Adds a `https://developer.android.com/reference/androidx/car/app/model/CarIcon` to be displayed as an `https://developer.android.com/reference/androidx/car/app/model/Banner#IMAGE_TYPE_MEDIUM()` image at the trailing part of the Banner, not expected to be tinted.

A banner can have at most 2 trailing elements.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `image` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if there are already 2 trailing elements |

### addTrailingImage

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

```
public @NonNull Banner.Builder addTrailingImage(@NonNull CarIcon image, int imageType)
```

Adds a `https://developer.android.com/reference/androidx/car/app/model/CarIcon` to be displayed as an image to the trailing part of the banner.

A banner can have at most 2 trailing elements.

A large image cannot be used in combination with `https://developer.android.com/reference/androidx/car/app/model/Banner.Builder#addBelowAction(androidx.car.app.model.Action)`.

A large trailing image cannot be used in combination with another large trailing image.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon image` | the `https://developer.android.com/reference/androidx/car/app/model/CarIcon` for the trailing image |
| `int imageType` | one of `https://developer.android.com/reference/androidx/car/app/model/Banner#IMAGE_TYPE_SMALL()`, `https://developer.android.com/reference/androidx/car/app/model/Banner#IMAGE_TYPE_MEDIUM()`, `https://developer.android.com/reference/androidx/car/app/model/Banner#IMAGE_TYPE_LARGE()` |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `image` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if there are already 2 trailing elements |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if a large trailing image is combined with anything other than a trailing small image or action |

### build

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

```
public @NonNull Banner build()
```

Constructs the `https://developer.android.com/reference/androidx/car/app/model/Banner` defined by this builder.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the title is null or empty |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if below actions are used in combination with a large image |

### setLeadingImage

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

```
public @NonNull Banner.Builder setLeadingImage(@NonNull CarIcon image)
```

Sets the leading element in this banner to be a `https://developer.android.com/reference/androidx/car/app/model/CarIcon` displayed as an `https://developer.android.com/reference/androidx/car/app/model/Banner#IMAGE_TYPE_MEDIUM()` image, not expected to be tinted.

Only a single leading image can be set. Subsequent calls will overwrite previous calls.

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

### setLeadingImage

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

```
public @NonNull Banner.Builder setLeadingImage(@NonNull CarIcon image, int imageType)
```

Sets the leading element in this banner to be a `https://developer.android.com/reference/androidx/car/app/model/CarIcon` displayed as an image.

Only a single leading icon or image can be set. Subsequent calls will overwrite previous calls.

A large image cannot be used in combination with `https://developer.android.com/reference/androidx/car/app/model/Banner.Builder#addBelowAction(androidx.car.app.model.Action)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon image` | the `https://developer.android.com/reference/androidx/car/app/model/CarIcon` for the leading image |
| `int imageType` | one of `https://developer.android.com/reference/androidx/car/app/model/Banner#IMAGE_TYPE_SMALL()`, `https://developer.android.com/reference/androidx/car/app/model/Banner#IMAGE_TYPE_MEDIUM()`, `https://developer.android.com/reference/androidx/car/app/model/Banner#IMAGE_TYPE_LARGE()` |

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

### setOnClickListener

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

```
public @NonNull Banner.Builder setOnClickListener(@NonNull OnClickListener onClickListener)
```

Sets the `https://developer.android.com/reference/androidx/car/app/model/OnClickListener` to be called back when the banner is clicked.

Note that the listener relates to UI events and will be executed on the main thread using `https://developer.android.com/reference/android/os/Looper.html#getMainLooper()`.

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

### setStyle

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

```
public @NonNull Banner.Builder setStyle(@NonNull BannerStyle style)
```

Sets the `https://developer.android.com/reference/androidx/car/app/model/BannerStyle` of the banner.

If a style is not provided via this method, a host default style will be used.

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

### setSubtitle

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

```
public @NonNull Banner.Builder setSubtitle(@NonNull CarText subtitle)
```

Sets the subtitle of the banner.

The subtitle allows spans to be added.

The subtitle is automatically truncated if it's too long.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `subtitle` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if any unsupported span types are added |

### setSubtitle

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

```
public @NonNull Banner.Builder setSubtitle(@NonNull CharSequence subtitle)
```

Sets the subtitle of the banner.

The subtitle allows spans to be added.

The subtitle is automatically truncated if it's too long.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `subtitle` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if any unsupported span types are added |

### setTitle

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

```
public @NonNull Banner.Builder setTitle(@NonNull CarText title)
```

Sets the title of the banner.

The title allows spans to be added.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `title` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if any unsupported span types are added |

### setTitle

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

```
public @NonNull Banner.Builder setTitle(@NonNull CharSequence title)
```

Sets the title of the banner.

The title allows spans to be added.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `title` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if any unsupported span types are added |