# CarToast

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

*** ** * ** ***


```
class CarToast
```

<br />

*** ** * ** ***

A message to show to the user for a short period of time.

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#LENGTH_LONG() = 1` Show the Toast view for a long period of time. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#LENGTH_SHORT() = 0` Show the Toast view for a short period of time. |

| ### Public functions |
|---|---|
| `java-static https://developer.android.com/reference/kotlin/androidx/car/app/CarToast` | `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#makeText(androidx.car.app.CarContext,java.lang.CharSequence,int)(carContext: https://developer.android.com/reference/kotlin/androidx/car/app/CarContext, text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html, duration: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Creates and sets the text and duration for the toast view. |
| `java-static https://developer.android.com/reference/kotlin/androidx/car/app/CarToast` | `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#makeText(androidx.car.app.CarContext,int,int)(carContext: https://developer.android.com/reference/kotlin/androidx/car/app/CarContext, textResId: @https://developer.android.com/reference/kotlin/androidx/annotation/StringRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, duration: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Creates and sets the text and duration for the toast view. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#setDuration(int)(duration: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets how long to show the toast for. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#setText(java.lang.CharSequence)(text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)` Sets the text for the toast. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#setText(int)(textResId: @https://developer.android.com/reference/kotlin/androidx/annotation/StringRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the text for the toast. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#show()()` Shows the toast with the specified text for the specified duration. |

## Constants

### LENGTH_LONG

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

```
const val LENGTH_LONG = 1: Int
```

Show the Toast view for a long period of time.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#setDuration(int)` |   |

### LENGTH_SHORT

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

```
const val LENGTH_SHORT = 0: Int
```

Show the Toast view for a short period of time. This is the default duration.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#setDuration(int)` |   |

## Public functions

### makeText

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

```
java-static fun makeText(carContext: CarContext, text: CharSequence, duration: Int): CarToast
```

Creates and sets the text and duration for the toast view.

| Parameters |
|---|---|
| `carContext: https://developer.android.com/reference/kotlin/androidx/car/app/CarContext` | the CarContext providing the service used to show the toast |
| `text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html` | the text to show |
| `duration: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | how long to display the message. Either `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#LENGTH_SHORT()` or `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#LENGTH_LONG()` |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if either the `carContext` or the `text` are ` null` |

### makeText

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

```
java-static fun makeText(carContext: CarContext, textResId: @StringRes Int, duration: Int): CarToast
```

Creates and sets the text and duration for the toast view.

| Parameters |
|---|---|
| `carContext: https://developer.android.com/reference/kotlin/androidx/car/app/CarContext` | the context used for string localization |
| `textResId: @https://developer.android.com/reference/kotlin/androidx/annotation/StringRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the resource id for the text to show. If the `textResId` is 0, the text will be set to empty |
| `duration: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | how long to display the message. Either `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#LENGTH_SHORT()` or `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#LENGTH_LONG()` |

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

### setDuration

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

```
fun setDuration(duration: Int): Unit
```

Sets how long to show the toast for.

| Parameters |
|---|---|
| `duration: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | how long to display the message. Either `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#LENGTH_SHORT()` or `https://developer.android.com/reference/kotlin/androidx/car/app/CarToast#LENGTH_LONG()` |

### setText

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

```
fun setText(text: CharSequence): Unit
```

Sets the text for the toast.

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

### setText

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

```
fun setText(textResId: @StringRes Int): Unit
```

Sets the text for the toast.

| Parameters |
|---|---|
| `textResId: @https://developer.android.com/reference/kotlin/androidx/annotation/StringRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the resource id for the text. If the `textResId` is 0, the text will be set to empty |

### show

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

```
fun show(): Unit
```

Shows the toast with the specified text for the specified duration.

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/HostException` | if the remote call fails |