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

*** ** * ** ***


```
class Tab.Builder
```

<br />

*** ** * ** ***

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

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab.Builder#Builder()()` Returns an empty `https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab.Builder` instance. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab.Builder#Builder(androidx.car.app.model.Tab)(tab: https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab)` Creates a new `https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab.Builder`, populated from the input `https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab`. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab.Builder#build()()` Constructs the `https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab` defined by this builder. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab.Builder#setContentId(java.lang.String)(contentId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Sets the content ID of the tab. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab.Builder#setIcon(androidx.car.app.model.CarIcon)(icon: https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIcon)` Sets the icon to display in the tab. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab.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/Tab.Builder#setStyle(androidx.car.app.model.TabStyle)(style: https://developer.android.com/reference/kotlin/androidx/car/app/model/TabStyle?)` Sets the style of the tab, or `null` to clear the style. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab.Builder` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/Tab.Builder#setTitle(java.lang.CharSequence)(title: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)` 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)

```
Builder()
```

Returns an empty `https://developer.android.com/reference/kotlin/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)

```
Builder(tab: Tab)
```

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

## Public functions

### build

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

```
fun build(): Tab
```

Constructs the `https://developer.android.com/reference/kotlin/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)

```
fun setContentId(contentId: String): Tab.Builder
```

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)

```
fun setIcon(icon: CarIcon): Tab.Builder
```

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/kotlin/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)
fun setStyle(style: TabStyle?): Tab.Builder
```

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)

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

Sets the title of the tab.

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` is empty, or if it contains unsupported spans |