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

*** ** * ** ***


```
public final class Tab.Builder
```

<br />

*** ** * ** ***

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

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/car/app/model/Tab.Builder#Builder()()` Returns an empty `https://developer.android.com/reference/androidx/car/app/model/Tab.Builder` instance. |
| `https://developer.android.com/reference/androidx/car/app/model/Tab.Builder#Builder(androidx.car.app.model.Tab)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Tab tab)` Creates a new `https://developer.android.com/reference/androidx/car/app/model/Tab.Builder`, populated from the input `https://developer.android.com/reference/androidx/car/app/model/Tab`. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Tab` | `https://developer.android.com/reference/androidx/car/app/model/Tab.Builder#build()()` Constructs the `https://developer.android.com/reference/androidx/car/app/model/Tab` defined by this builder. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Tab.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Tab.Builder#setContentId(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html contentId)` Sets the content ID of the tab. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Tab.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Tab.Builder#setIcon(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 icon)` Sets the icon to display in the tab. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Tab.Builder` | `@https://developer.android.com/reference/androidx/car/app/annotations/ExperimentalCarApi @https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 9) https://developer.android.com/reference/androidx/car/app/model/Tab.Builder#setStyle(androidx.car.app.model.TabStyle)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/TabStyle style)` Sets the style of the tab, or `null` to clear the style. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Tab.Builder` | `https://developer.android.com/reference/androidx/car/app/model/Tab.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 tab. |

## Public constructors

### Builder

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

```
public Builder()
```

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

### Builder

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

```
public Builder(@NonNull Tab tab)
```

Creates a new `https://developer.android.com/reference/androidx/car/app/model/Tab.Builder`, populated from the input `https://developer.android.com/reference/androidx/car/app/model/Tab`.

## Public methods

### build

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

```
public @NonNull Tab build()
```

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

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the tab's title, icon or content ID is not set. |

### setContentId

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

```
public @NonNull Tab.Builder setContentId(@NonNull String contentId)
```

Sets the content ID of the tab.

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

### setIcon

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

```
public @NonNull Tab.Builder setIcon(@NonNull CarIcon icon)
```

Sets the icon to display in the tab.

#### Icon Sizing Guidance

To minimize scaling artifacts across a wide range of car screens, apps should provide icons targeting a 36 x 36 dp bounding box. If the icon exceeds this maximum size in either one of the dimensions, it will be scaled down to be centered inside the bounding box while preserving its aspect ratio.

See `https://developer.android.com/reference/androidx/car/app/model/CarIcon` for more details related to providing icon and image resources that work with different car screen pixel densities.

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

### setStyle

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

```
@ExperimentalCarApi
@RequiresCarApi(value = 9)
public @NonNull Tab.Builder setStyle(@Nullable TabStyle style)
```

Sets the style of the tab, or `null` to clear the style.

If a style is not set or is cleared, the tab style will fall back to host defaults.

### setTitle

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

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

Sets the title of the tab.

Only `https://developer.android.com/reference/androidx/car/app/model/DistanceSpan`s and `https://developer.android.com/reference/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` is empty, or if it contains unsupported spans |