public final class

CarAlertDialog.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.car.app.CarAlertDialog.Builder

Overview

Builder class that can be used to create a CarAlertDialog by configuring the options for what shows up in the resulting dialog.

Summary

Constructors
publicBuilder(Context context)

Creates a new instance of the Builder.

Methods
public CarAlertDialogcreate()

Creates an CarAlertDialog with the arguments supplied to this Builder.

public CarAlertDialog.BuildersetBody(java.lang.CharSequence body)

Sets the body text of the dialog to be the given string.

public CarAlertDialog.BuildersetBody(int bodyId)

Sets the body text of the dialog to be the given string resource.

public CarAlertDialog.BuildersetBodyMovementMethod(MovementMethod movementMethod)

Sets the to be applied on the body text of this alert dialog.

public CarAlertDialog.BuildersetCancelable(boolean cancelable)

Sets whether the dialog is cancelable or not.

public CarAlertDialog.BuildersetHeaderIcon(Icon icon)

Sets the header icon of the dialog to be the given Icon.

public CarAlertDialog.BuildersetHeaderIcon(int iconId)

Sets the header icon of the dialog to be the given int resource id.

public CarAlertDialog.BuildersetNegativeButton(java.lang.CharSequence text, OnClickListener listener)

Sets the text of the negative button and the listener that will be invoked when the button is pressed.

public CarAlertDialog.BuildersetNegativeButton(int textId, OnClickListener listener)

Sets the text of the negative button and the listener that will be invoked when the button is pressed.

public CarAlertDialog.BuildersetOnCancelListener(OnCancelListener onCancelListener)

Sets the callback that will be called if the dialog is canceled.

public CarAlertDialog.BuildersetOnDismissListener(OnDismissListener onDismissListener)

Sets the callback that will be called when the dialog is dismissed for any reason.

public CarAlertDialog.BuildersetPositiveButton(java.lang.CharSequence text, OnClickListener listener)

Sets the text of the positive button and the listener that will be invoked when the button is pressed.

public CarAlertDialog.BuildersetPositiveButton(int textId, OnClickListener listener)

Sets the text of the positive button and the listener that will be invoked when the button is pressed.

public CarAlertDialog.BuildersetTitle(java.lang.CharSequence title)

Sets the main title of the dialog for be the given string.

public CarAlertDialog.BuildersetTitle(int titleId)

Sets the main title of the dialog to be the given string resource.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(Context context)

Creates a new instance of the Builder.

Parameters:

context: The Context that the dialog is to be created in.

Methods

public CarAlertDialog.Builder setHeaderIcon(int iconId)

Sets the header icon of the dialog to be the given int resource id. Passing-in an invalid id will throw a NotFoundException.

Parameters:

iconId: The resource id of the Icon to be used as the header icon.

Returns:

This Builder object to allow for chaining of calls.

public CarAlertDialog.Builder setHeaderIcon(Icon icon)

Sets the header icon of the dialog to be the given Icon. Passing-in a null icon will hide the ImageView in the header.

Parameters:

icon: The Icon to be used as the header icon.

Returns:

This Builder object to allow for chaining of calls.

public CarAlertDialog.Builder setTitle(int titleId)

Sets the main title of the dialog to be the given string resource.

Parameters:

titleId: The resource id of the string to be used as the title.

Returns:

This Builder object to allow for chaining of calls.

public CarAlertDialog.Builder setTitle(java.lang.CharSequence title)

Sets the main title of the dialog for be the given string.

Parameters:

title: The string to be used as the title.

Returns:

This Builder object to allow for chaining of calls.

public CarAlertDialog.Builder setBody(int bodyId)

Sets the body text of the dialog to be the given string resource.

Parameters:

bodyId: The resource id of the string to be used as the body text.

Returns:

This Builder object to allow for chaining of calls.

public CarAlertDialog.Builder setBody(java.lang.CharSequence body)

Sets the body text of the dialog to be the given string.

Parameters:

body: The string to be used as the body text.

Returns:

This Builder object to allow for chaining of calls.

public CarAlertDialog.Builder setBodyMovementMethod(MovementMethod movementMethod)

Sets the to be applied on the body text of this alert dialog.

Parameters:

movementMethod: The MovementMethod to apply or null.

Returns:

This Builder object to allow for chaining of calls.

See also: TextView

public CarAlertDialog.Builder setPositiveButton(int textId, OnClickListener listener)

Sets the text of the positive button and the listener that will be invoked when the button is pressed. If a listener is not provided, then the dialog will dismiss itself when the positive button is clicked.

The positive button should be used to accept and continue with the action (e.g. an "OK" action).

Parameters:

textId: The resource id of the string to be used for the positive button text.
listener: A to be invoked when the button is clicked. Can be null to represent no listener.

Returns:

This Builder object to allow for chaining of calls.

public CarAlertDialog.Builder setPositiveButton(java.lang.CharSequence text, OnClickListener listener)

Sets the text of the positive button and the listener that will be invoked when the button is pressed. If a listener is not provided, then the dialog will dismiss itself when the positive button is clicked.

The positive button should be used to accept and continue with the action (e.g. an "OK" action).

Parameters:

text: The string to be used for the positive button text.
listener: A to be invoked when the button is clicked. Can be null to represent no listener.

Returns:

This Builder object to allow for chaining of calls.

public CarAlertDialog.Builder setNegativeButton(int textId, OnClickListener listener)

Sets the text of the negative button and the listener that will be invoked when the button is pressed. If a listener is not provided, then the dialog will dismiss itself when the negative button is clicked.

The negative button should be used to cancel any actions the dialog represents.

Parameters:

textId: The resource id of the string to be used for the negative button text.
listener: A to be invoked when the button is clicked. Can be null to represent no listener.

Returns:

This Builder object to allow for chaining of calls.

public CarAlertDialog.Builder setNegativeButton(java.lang.CharSequence text, OnClickListener listener)

Sets the text of the negative button and the listener that will be invoked when the button is pressed. If a listener is not provided, then the dialog will dismiss itself when the negative button is clicked.

The negative button should be used to cancel any actions the dialog represents.

Parameters:

text: The string to be used for the negative button text.
listener: A to be invoked when the button is clicked. Can be null to represent no listener.

Returns:

This Builder object to allow for chaining of calls.

public CarAlertDialog.Builder setCancelable(boolean cancelable)

Sets whether the dialog is cancelable or not. Default is true.

Returns:

This Builder object to allow for chaining of calls.

public CarAlertDialog.Builder setOnCancelListener(OnCancelListener onCancelListener)

Sets the callback that will be called if the dialog is canceled.

Even in a cancelable dialog, the dialog may be dismissed for reasons other than being canceled or one of the supplied choices being selected. If you are interested in listening for all cases where the dialog is dismissed and not just when it is canceled, see CarAlertDialog.Builder.setOnDismissListener(OnDismissListener).

Parameters:

onCancelListener: The listener to be invoked when this dialog is canceled.

Returns:

This Builder object to allow for chaining of calls.

See also: CarAlertDialog.Builder.setCancelable(boolean), CarAlertDialog.Builder.setOnDismissListener(OnDismissListener)

public CarAlertDialog.Builder setOnDismissListener(OnDismissListener onDismissListener)

Sets the callback that will be called when the dialog is dismissed for any reason.

Returns:

This Builder object to allow for chaining of calls.

public CarAlertDialog create()

Creates an CarAlertDialog with the arguments supplied to this Builder.

Calling this method does not display the dialog. Utilize this dialog within a DialogFragment to show the dialog.