CarToast


public final class CarToast


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

Summary

Constants

static final int

Show the Toast view for a long period of time.

static final int

Show the Toast view for a short period of time.

Public methods

static @NonNull CarToast
makeText(
    @NonNull CarContext carContext,
    @NonNull CharSequence text,
    int duration
)

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

static @NonNull CarToast
makeText(
    @NonNull CarContext carContext,
    @StringRes int textResId,
    int duration
)

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

void
setDuration(int duration)

Sets how long to show the toast for.

void

Sets the text for the toast.

void
setText(@StringRes int textResId)

Sets the text for the toast.

void

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

Constants

LENGTH_LONG

Added in 1.0.0
public static final int LENGTH_LONG = 1

Show the Toast view for a long period of time.

See also
setDuration

LENGTH_SHORT

Added in 1.0.0
public static final int LENGTH_SHORT = 0

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

See also
setDuration

Public methods

makeText

Added in 1.0.0
public static @NonNull CarToast makeText(
    @NonNull CarContext carContext,
    @NonNull CharSequence text,
    int duration
)

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

Parameters
@NonNull CharSequence text

the text to show

int duration

how long to display the message. Either LENGTH_SHORT or LENGTH_LONG

Throws
java.lang.NullPointerException

if either the carContext or the text are null

makeText

Added in 1.0.0
public static @NonNull CarToast makeText(
    @NonNull CarContext carContext,
    @StringRes int textResId,
    int duration
)

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

Parameters
@StringRes int textResId

the resource id for the text to show. If the textResId is 0, the text will be set to empty

int duration

how long to display the message. Either LENGTH_SHORT or LENGTH_LONG

Throws
java.lang.NullPointerException

if carContext is null

setDuration

Added in 1.0.0
public void setDuration(int duration)

Sets how long to show the toast for.

Parameters
int duration

how long to display the message. Either LENGTH_SHORT or LENGTH_LONG

setText

Added in 1.0.0
public void setText(@NonNull CharSequence text)

Sets the text for the toast.

Throws
java.lang.NullPointerException

if text is null

setText

Added in 1.0.0
public void setText(@StringRes int textResId)

Sets the text for the toast.

Parameters
@StringRes int textResId

the resource id for the text. If the textResId is 0, the text will be set to empty

show

Added in 1.0.0
public void show()

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

Throws
androidx.car.app.HostException

if the remote call fails