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

*** ** * ** ***


```
public final class Background.Builder
```

<br />

*** ** * ** ***

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

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/car/app/model/Background.Builder#Builder()()` Returns an empty `https://developer.android.com/reference/androidx/car/app/model/Background.Builder` instance. |
| `https://developer.android.com/reference/androidx/car/app/model/Background.Builder#Builder(androidx.car.app.model.Background)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Background background)` Returns a new `https://developer.android.com/reference/androidx/car/app/model/Background.Builder` with the data from the given `https://developer.android.com/reference/androidx/car/app/model/Background` instance. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Background` | `https://developer.android.com/reference/androidx/car/app/model/Background.Builder#build()()` Constructs the `https://developer.android.com/reference/androidx/car/app/model/Background` defined by this builder. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Background.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Background.Builder#setColor(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 color)` Sets the `https://developer.android.com/reference/androidx/car/app/model/CarColor` to be used for the background. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Background.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Background.Builder#setImage(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 `https://developer.android.com/reference/androidx/car/app/model/CarIcon` that will be displayed as the background. |

## Public constructors

### Builder

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

```
public Builder()
```

Returns an empty `https://developer.android.com/reference/androidx/car/app/model/Background.Builder` instance.

### Builder

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

```
public Builder(@NonNull Background background)
```

Returns a new `https://developer.android.com/reference/androidx/car/app/model/Background.Builder` with the data from the given `https://developer.android.com/reference/androidx/car/app/model/Background` instance.

## Public methods

### build

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

```
public @NonNull Background build()
```

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

Ensures that exactly one of either an image or a color is set for the background.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if neither an image nor a color is set, or if both an image and a color are set. |

### setColor

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

```
public @NonNull Background.Builder setColor(@NonNull CarColor color)
```

Sets the `https://developer.android.com/reference/androidx/car/app/model/CarColor` to be used for the background.

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

### setImage

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

```
public @NonNull Background.Builder setImage(@NonNull CarIcon image)
```

Sets the `https://developer.android.com/reference/androidx/car/app/model/CarIcon` that will be displayed as the background.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `image` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `image` is not of type `https://developer.android.com/reference/androidx/car/app/model/CarIcon#TYPE_CUSTOM()` |