Register now for Android Dev Summit 2019!

Builder

class Builder
kotlin.Any
   ↳ androidx.car.app.CarAlertDialog.Builder

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

Summary

Public constructors

<init>(context: Context!)

Creates a new instance of the Builder.

Public methods

CarAlertDialog!

Creates an CarAlertDialog with the arguments supplied to this Builder.

CarAlertDialog.Builder!
setBody(@StringRes bodyId: Int)

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

CarAlertDialog.Builder!

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

CarAlertDialog.Builder!
setBodyMovementMethod(@Nullable movementMethod: MovementMethod?)

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

CarAlertDialog.Builder!
setCancelable(cancelable: Boolean)

Sets whether the dialog is cancelable or not.

CarAlertDialog.Builder
setHeaderIcon(@DrawableRes iconId: Int)

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

CarAlertDialog.Builder
setHeaderIcon(@Nullable icon: Icon?)

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

CarAlertDialog.Builder!
setNegativeButton(@StringRes textId: Int, @Nullable listener: OnClickListener?)

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

CarAlertDialog.Builder!
setNegativeButton(text: CharSequence!, @Nullable listener: OnClickListener?)

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

CarAlertDialog.Builder!

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

CarAlertDialog.Builder!

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

CarAlertDialog.Builder!
setPositiveButton(@StringRes textId: Int, @Nullable listener: OnClickListener?)

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

CarAlertDialog.Builder!
setPositiveButton(text: CharSequence!, @Nullable listener: OnClickListener?)

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

CarAlertDialog.Builder!
setTitle(@StringRes titleId: Int)

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

CarAlertDialog.Builder!

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

Public constructors

<init>

Builder(context: Context!)

Creates a new instance of the Builder.

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

Public methods

create

fun create(): CarAlertDialog!

Creates an CarAlertDialog with the arguments supplied to this Builder.

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

setBody

fun setBody(@StringRes bodyId: Int): CarAlertDialog.Builder!

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

Parameters
bodyId Int: The resource id of the string to be used as the body text.
Return
CarAlertDialog.Builder!: This Builder object to allow for chaining of calls.

setBody

fun setBody(body: CharSequence!): CarAlertDialog.Builder!

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

Parameters
body CharSequence!: The string to be used as the body text.
Return
CarAlertDialog.Builder!: This Builder object to allow for chaining of calls.

setBodyMovementMethod

fun setBodyMovementMethod(@Nullable movementMethod: MovementMethod?): CarAlertDialog.Builder!

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

Parameters
movementMethod MovementMethod?: The MovementMethod to apply or null.
Return
CarAlertDialog.Builder!: This Builder object to allow for chaining of calls.

setCancelable

fun setCancelable(cancelable: Boolean): CarAlertDialog.Builder!

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

Return
CarAlertDialog.Builder!: This Builder object to allow for chaining of calls.

setHeaderIcon

@NonNull fun setHeaderIcon(@DrawableRes iconId: Int): CarAlertDialog.Builder

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 Int: The resource id of the Icon to be used as the header icon.
Return
CarAlertDialog.Builder: This Builder object to allow for chaining of calls.

setHeaderIcon

@NonNull fun setHeaderIcon(@Nullable icon: Icon?): CarAlertDialog.Builder

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 Icon?: The Icon to be used as the header icon.
Return
CarAlertDialog.Builder: This Builder object to allow for chaining of calls.

setNegativeButton

fun setNegativeButton(@StringRes textId: Int, @Nullable listener: OnClickListener?): CarAlertDialog.Builder!

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 Int: The resource id of the string to be used for the negative button text.
listener Int: A android.content.DialogInterface.OnClickListener to be invoked when the button is clicked. Can be null to represent no listener.
Return
CarAlertDialog.Builder!: This Builder object to allow for chaining of calls.

setNegativeButton

fun setNegativeButton(text: CharSequence!, @Nullable listener: OnClickListener?): CarAlertDialog.Builder!

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 CharSequence!: The string to be used for the negative button text.
listener CharSequence!: A android.content.DialogInterface.OnClickListener to be invoked when the button is clicked. Can be null to represent no listener.
Return
CarAlertDialog.Builder!: This Builder object to allow for chaining of calls.

setOnCancelListener

fun setOnCancelListener(onCancelListener: OnCancelListener!): CarAlertDialog.Builder!

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 setOnDismissListener(OnDismissListener).

Parameters
onCancelListener OnCancelListener!: The listener to be invoked when this dialog is canceled.
Return
CarAlertDialog.Builder!: This Builder object to allow for chaining of calls.

setOnDismissListener

fun setOnDismissListener(onDismissListener: OnDismissListener!): CarAlertDialog.Builder!

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

Return
CarAlertDialog.Builder!: This Builder object to allow for chaining of calls.

setPositiveButton

fun setPositiveButton(@StringRes textId: Int, @Nullable listener: OnClickListener?): CarAlertDialog.Builder!

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 Int: The resource id of the string to be used for the positive button text.
listener Int: A android.content.DialogInterface.OnClickListener to be invoked when the button is clicked. Can be null to represent no listener.
Return
CarAlertDialog.Builder!: This Builder object to allow for chaining of calls.

setPositiveButton

fun setPositiveButton(text: CharSequence!, @Nullable listener: OnClickListener?): CarAlertDialog.Builder!

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 CharSequence!: The string to be used for the positive button text.
listener CharSequence!: A android.content.DialogInterface.OnClickListener to be invoked when the button is clicked. Can be null to represent no listener.
Return
CarAlertDialog.Builder!: This Builder object to allow for chaining of calls.

setTitle

fun setTitle(@StringRes titleId: Int): CarAlertDialog.Builder!

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

Parameters
titleId Int: The resource id of the string to be used as the title.
Return
CarAlertDialog.Builder!: This Builder object to allow for chaining of calls.

setTitle

fun setTitle(title: CharSequence!): CarAlertDialog.Builder!

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

Parameters
title CharSequence!: The string to be used as the title.
Return
CarAlertDialog.Builder!: This Builder object to allow for chaining of calls.