# AlertDialog

Artifact: [androidx.appcompat:appcompat](https://developer.android.com/jetpack/androidx/releases/appcompat) [View Source](https://cs.android.com/search?q=file:androidx/appcompat/app/AlertDialog.java+class:androidx.appcompat.app.AlertDialog) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

*** ** * ** ***


```
public class AlertDialog extends AppCompatDialog implements DialogInterface
```

<br />

|---|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||||
| ↳ | [android.app.Dialog](https://developer.android.com/reference/android/app/Dialog.html) ||||
|   | ↳ | [androidx.activity.ComponentDialog](https://developer.android.com/reference/androidx/activity/ComponentDialog) |||
|   |   | ↳ | [androidx.appcompat.app.AppCompatDialog](https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog) ||
|   |   |   | ↳ | [androidx.appcompat.app.AlertDialog](https://developer.android.com/reference/androidx/appcompat/app/AlertDialog) |

Known direct subclasses [MediaRouteControllerDialog](https://developer.android.com/reference/androidx/mediarouter/app/MediaRouteControllerDialog)

|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/app/MediaRouteControllerDialog` | This class implements the route controller dialog for `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter`. |

*** ** * ** ***

A subclass of Dialog that can display one, two or three buttons. If you only want to display a String in this dialog box, use the setMessage() method. If you want to display a more complex view, look up the FrameLayout called "custom" and add your view to it:

```
FrameLayout fl = findViewById(android.R.id.custom);
fl.addView(myView, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
```

The AlertDialog class takes care of automatically setting `https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_ALT_FOCUSABLE_IM` for you based on whether any views in the dialog return true from `https://developer.android.com/reference/android/view/View.html#onCheckIsTextEditor()`. Generally you want this set for a Dialog without text editors, so that it will be placed on top of the current input method UI. You can modify this behavior by forcing the flag to your desired mode after calling `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#onCreate(android.os.Bundle)`.

## Summary

| ### Nested types |
|---|
| `public class https://developer.android.com/reference/androidx/appcompat/app/AlertDialog.Builder` |

| ### Protected constructors |
|---|
| `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#AlertDialog(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` |
| `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#AlertDialog(android.content.Context,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/StyleRes int themeResId)` Construct an AlertDialog that uses an explicit theme. |
| `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#AlertDialog(android.content.Context,boolean,android.content.DialogInterface.OnCancelListener)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, boolean cancelable, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/DialogInterface.OnCancelListener.html cancelListener )` |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/android/widget/Button.html` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#getButton(int)(int whichButton)` Gets one of the buttons used in the dialog. |
| `https://developer.android.com/reference/android/widget/ListView.html` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#getListView()()` Gets the list view used in the dialog. |
| `boolean` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#onKeyDown(int,android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent.html event)` |
| `boolean` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#onKeyUp(int,android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent.html event)` |
| `void` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#setButton(int,java.lang.CharSequence,android.content.DialogInterface.OnClickListener)( int whichButton, https://developer.android.com/reference/java/lang/CharSequence.html text, https://developer.android.com/reference/android/content/DialogInterface.OnClickListener.html listener )` Sets a listener to be invoked when the positive button of the dialog is pressed. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#setButton(int,java.lang.CharSequence,android.os.Message)(int whichButton, https://developer.android.com/reference/java/lang/CharSequence.html text, https://developer.android.com/reference/android/os/Message.html msg)` Sets a message to be sent when a button is pressed. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#setButton(int,java.lang.CharSequence,android.graphics.drawable.Drawable,android.content.DialogInterface.OnClickListener)( int whichButton, https://developer.android.com/reference/java/lang/CharSequence.html text, https://developer.android.com/reference/android/graphics/drawable/Drawable.html icon, https://developer.android.com/reference/android/content/DialogInterface.OnClickListener.html listener )` Sets an icon to be displayed along with the button text and a listener to be invoked when the positive button of the dialog is pressed. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#setCustomTitle(android.view.View)(https://developer.android.com/reference/android/view/View.html customTitleView)` This method has no effect if called after `https://developer.android.com/reference/android/app/Dialog.html#show()`. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#setIcon(android.graphics.drawable.Drawable)(https://developer.android.com/reference/android/graphics/drawable/Drawable.html icon)` Set the `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` to be used in the title. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#setIcon(int)(int resId)` Set resId to 0 if you don't want an icon. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#setIconAttribute(int)(int attrId)` Sets an icon as supplied by a theme attribute. e.g. android.R.attr.alertDialogIcon |
| `void` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#setMessage(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence.html message)` Sets the message to display. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#setTitle(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence.html title)` |
| `void` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#setView(android.view.View)(https://developer.android.com/reference/android/view/View.html view)` Set the view to display in the dialog. |
| `void` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#setView(android.view.View,int,int,int,int)( https://developer.android.com/reference/android/view/View.html view, int viewSpacingLeft, int viewSpacingTop, int viewSpacingRight, int viewSpacingBottom )` Set the view to display in the dialog, specifying the spacing to appear around that view. |

| ### Protected methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog#onCreate(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html savedInstanceState)` |

### Inherited Constants

From [android.content.DialogInterface](https://developer.android.com/reference/android/content/DialogInterface.html) `static final int` `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON1 = -1`

**This field is deprecated.**
`static final int` `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON2 = -2`

**This field is deprecated.**
`static final int` `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON3 = -3`

**This field is deprecated.**
`static final int` `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON_NEGATIVE = -2` `static final int` `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON_NEUTRAL = -3` `static final int` `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON_POSITIVE = -1`

### Inherited methods

From [androidx.appcompat.app.AppCompatDialog](https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog) `void` `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog#addContentView(android.view.View,android.view.ViewGroup.LayoutParams)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html view, https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html params)` `void` `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog#dismiss()()` `boolean` `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog#dispatchKeyEvent(android.view.KeyEvent)(https://developer.android.com/reference/android/view/KeyEvent.html event)` `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html T` `<T extends https://developer.android.com/reference/android/view/View.html> https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog#findViewById(int)(@https://developer.android.com/reference/androidx/annotation/IdRes int id)` `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appcompat/app/AppCompatDelegate` `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog#getDelegate()()` `https://developer.android.com/reference/androidx/appcompat/app/ActionBar` `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog#getSupportActionBar()()`

Support library version of `https://developer.android.com/reference/android/app/Dialog.html#getActionBar()`.
`void` `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog#onStop()()` `void` `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog#onSupportActionModeFinished(androidx.appcompat.view.ActionMode)(https://developer.android.com/reference/androidx/appcompat/view/ActionMode mode)`

Called when a support action mode has finished.
`void` `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog#onSupportActionModeStarted(androidx.appcompat.view.ActionMode)(https://developer.android.com/reference/androidx/appcompat/view/ActionMode mode)`

Called when a support action mode has been started.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/appcompat/view/ActionMode` `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog#onWindowStartingSupportActionMode(androidx.appcompat.view.ActionMode.Callback)(https://developer.android.com/reference/androidx/appcompat/view/ActionMode.Callback callback)`

Called when a support action mode is being started for this window.
`void` `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog#setContentView(int)(@https://developer.android.com/reference/androidx/annotation/LayoutRes int layoutResID)` `void` `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog#setContentView(android.view.View)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html view)` `void` `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog#setContentView(android.view.View,android.view.ViewGroup.LayoutParams)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html view, https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html params)` `void` `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog#setTitle(int)(int titleId)` `boolean` `https://developer.android.com/reference/androidx/appcompat/app/AppCompatDialog#supportRequestWindowFeature(int)(int featureId)`

Enable extended support library window features.
From [androidx.activity.ComponentDialog](https://developer.android.com/reference/androidx/activity/ComponentDialog) `void` `https://developer.android.com/reference/androidx/activity/ComponentDialog#addContentView(android.view.View,android.view.ViewGroup.LayoutParams)(https://developer.android.com/reference/android/view/View.html view, https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html params)` `https://developer.android.com/reference/androidx/lifecycle/Lifecycle` `https://developer.android.com/reference/androidx/activity/ComponentDialog#getLifecycle()()`

The `https://developer.android.com/reference/androidx/lifecycle/Lifecycle` of this owner.
`https://developer.android.com/reference/androidx/navigationevent/NavigationEventDispatcher` `https://developer.android.com/reference/androidx/activity/ComponentDialog#getNavigationEventDispatcher()()`

Lazily provides a `https://developer.android.com/reference/androidx/navigationevent/NavigationEventDispatcher` for back navigation handling, including support for predictive back gestures introduced in Android 13 (API 33+).
`final https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcher` `https://developer.android.com/reference/androidx/activity/ComponentDialog#getOnBackPressedDispatcher()()`

Retrieve the `https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcher` that will be triggered when `https://developer.android.com/reference/androidx/activity/ComponentDialog#onBackPressed()` is called.
`https://developer.android.com/reference/androidx/savedstate/SavedStateRegistry` `https://developer.android.com/reference/androidx/activity/ComponentDialog#getSavedStateRegistry()()`

The `https://developer.android.com/reference/androidx/savedstate/SavedStateRegistry` owned by this `https://developer.android.com/reference/androidx/savedstate/SavedStateRegistryOwner`.
`void` `https://developer.android.com/reference/androidx/activity/ComponentDialog#initializeViewTreeOwners()()`

Sets the view tree owners before setting the content view so that the inflation process and attach listeners will see them already present.
`void` `https://developer.android.com/reference/androidx/activity/ComponentDialog#onBackPressed()()`

**This method is deprecated.**
`void` `https://developer.android.com/reference/androidx/activity/ComponentDialog#onCreate(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html savedInstanceState)` `https://developer.android.com/reference/android/os/Bundle.html` `https://developer.android.com/reference/androidx/activity/ComponentDialog#onSaveInstanceState()()` `void` `https://developer.android.com/reference/androidx/activity/ComponentDialog#onStart()()` `void` `https://developer.android.com/reference/androidx/activity/ComponentDialog#onStop()()` `void` `https://developer.android.com/reference/androidx/activity/ComponentDialog#setContentView(int)(int layoutResID)` From [android.app.Dialog](https://developer.android.com/reference/android/app/Dialog.html) `void` `https://developer.android.com/reference/android/app/Dialog.html#addContentView(android.view.View, android.view.ViewGroup.LayoutParams)(https://developer.android.com/reference/android/view/View.html view, https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html params)` `void` `https://developer.android.com/reference/android/app/Dialog.html#closeOptionsMenu()()` `void` `https://developer.android.com/reference/android/app/Dialog.html#create()()` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#dispatchGenericMotionEvent(android.view.MotionEvent)(https://developer.android.com/reference/android/view/MotionEvent.html ev)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#dispatchKeyEvent(android.view.KeyEvent)(https://developer.android.com/reference/android/view/KeyEvent.html event)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#dispatchKeyShortcutEvent(android.view.KeyEvent)(https://developer.android.com/reference/android/view/KeyEvent.html event)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#dispatchPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent)(https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html event)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#dispatchTouchEvent(android.view.MotionEvent)(https://developer.android.com/reference/android/view/MotionEvent.html ev)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#dispatchTrackballEvent(android.view.MotionEvent)(https://developer.android.com/reference/android/view/MotionEvent.html ev)` `T` `<T extends https://developer.android.com/reference/android/view/View.html> https://developer.android.com/reference/android/app/Dialog.html#findViewById(int)(int id)` `https://developer.android.com/reference/android/app/ActionBar.html` `https://developer.android.com/reference/android/app/Dialog.html#getActionBar()()` `final https://developer.android.com/reference/android/content/Context.html` `https://developer.android.com/reference/android/app/Dialog.html#getContext()()` `https://developer.android.com/reference/android/view/View.html` `https://developer.android.com/reference/android/app/Dialog.html#getCurrentFocus()()` `https://developer.android.com/reference/android/view/LayoutInflater.html` `https://developer.android.com/reference/android/app/Dialog.html#getLayoutInflater()()` `https://developer.android.com/reference/android/window/OnBackInvokedDispatcher.html` `https://developer.android.com/reference/android/app/Dialog.html#getOnBackInvokedDispatcher()()` `final https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/android/app/Dialog.html#getOwnerActivity()()` `final https://developer.android.com/reference/android/view/SearchEvent.html` `https://developer.android.com/reference/android/app/Dialog.html#getSearchEvent()()` `final int` `https://developer.android.com/reference/android/app/Dialog.html#getVolumeControlStream()()` `https://developer.android.com/reference/android/view/Window.html` `https://developer.android.com/reference/android/app/Dialog.html#getWindow()()` `void` `https://developer.android.com/reference/android/app/Dialog.html#hide()()` `void` `https://developer.android.com/reference/android/app/Dialog.html#invalidateOptionsMenu()()` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#isShowing()()` `void` `https://developer.android.com/reference/android/app/Dialog.html#onActionModeFinished(android.view.ActionMode)(https://developer.android.com/reference/android/view/ActionMode.html mode)` `void` `https://developer.android.com/reference/android/app/Dialog.html#onActionModeStarted(android.view.ActionMode)(https://developer.android.com/reference/android/view/ActionMode.html mode)` `void` `https://developer.android.com/reference/android/app/Dialog.html#onAttachedToWindow()()` `void` `https://developer.android.com/reference/android/app/Dialog.html#onBackPressed()()`

**This method is deprecated.**
`void` `https://developer.android.com/reference/android/app/Dialog.html#onContentChanged()()` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#onContextItemSelected(android.view.MenuItem)(https://developer.android.com/reference/android/view/MenuItem.html item)` `void` `https://developer.android.com/reference/android/app/Dialog.html#onContextMenuClosed(android.view.Menu)(https://developer.android.com/reference/android/view/Menu.html menu)` `void` `https://developer.android.com/reference/android/app/Dialog.html#onCreate(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html savedInstanceState)` `void` `https://developer.android.com/reference/android/app/Dialog.html#onCreateContextMenu(android.view.ContextMenu, android.view.View, android.view.ContextMenu.ContextMenuInfo)(
https://developer.android.com/reference/android/view/ContextMenu.html menu,
https://developer.android.com/reference/android/view/View.html v,
https://developer.android.com/reference/android/view/ContextMenu.ContextMenuInfo.html menuInfo
)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#onCreateOptionsMenu(android.view.Menu)(https://developer.android.com/reference/android/view/Menu.html menu)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#onCreatePanelMenu(int, android.view.Menu)(int featureId, https://developer.android.com/reference/android/view/Menu.html menu)` `https://developer.android.com/reference/android/view/View.html` `https://developer.android.com/reference/android/app/Dialog.html#onCreatePanelView(int)(int featureId)` `void` `https://developer.android.com/reference/android/app/Dialog.html#onDetachedFromWindow()()` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#onGenericMotionEvent(android.view.MotionEvent)(https://developer.android.com/reference/android/view/MotionEvent.html event)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#onKeyLongPress(int, android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent.html event)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#onKeyMultiple(int, int, android.view.KeyEvent)(int keyCode, int repeatCount, https://developer.android.com/reference/android/view/KeyEvent.html event)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#onKeyShortcut(int, android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent.html event)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#onMenuItemSelected(int, android.view.MenuItem)(int featureId, https://developer.android.com/reference/android/view/MenuItem.html item)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#onMenuOpened(int, android.view.Menu)(int featureId, https://developer.android.com/reference/android/view/Menu.html menu)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#onOptionsItemSelected(android.view.MenuItem)(https://developer.android.com/reference/android/view/MenuItem.html item)` `void` `https://developer.android.com/reference/android/app/Dialog.html#onOptionsMenuClosed(android.view.Menu)(https://developer.android.com/reference/android/view/Menu.html menu)` `void` `https://developer.android.com/reference/android/app/Dialog.html#onPanelClosed(int, android.view.Menu)(int featureId, https://developer.android.com/reference/android/view/Menu.html menu)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#onPrepareOptionsMenu(android.view.Menu)(https://developer.android.com/reference/android/view/Menu.html menu)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#onPreparePanel(int, android.view.View, android.view.Menu)(int featureId, https://developer.android.com/reference/android/view/View.html view, https://developer.android.com/reference/android/view/Menu.html menu)` `void` `https://developer.android.com/reference/android/app/Dialog.html#onRestoreInstanceState(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html savedInstanceState)` `https://developer.android.com/reference/android/os/Bundle.html` `https://developer.android.com/reference/android/app/Dialog.html#onSaveInstanceState()()` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#onSearchRequested()()` `void` `https://developer.android.com/reference/android/app/Dialog.html#onStart()()` `void` `https://developer.android.com/reference/android/app/Dialog.html#onStop()()` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#onTouchEvent(android.view.MotionEvent)(https://developer.android.com/reference/android/view/MotionEvent.html event)` `boolean` `https://developer.android.com/reference/android/app/Dialog.html#onTrackballEvent(android.view.MotionEvent)(https://developer.android.com/reference/android/view/MotionEvent.html event)` `void` `https://developer.android.com/reference/android/app/Dialog.html#onWindowAttributesChanged(android.view.WindowManager.LayoutParams)(https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html params)` `void` `https://developer.android.com/reference/android/app/Dialog.html#onWindowFocusChanged(boolean)(boolean hasFocus)` `https://developer.android.com/reference/android/view/ActionMode.html` `https://developer.android.com/reference/android/app/Dialog.html#onWindowStartingActionMode(android.view.ActionMode.Callback)(https://developer.android.com/reference/android/view/ActionMode.Callback.html callback)` `void` `https://developer.android.com/reference/android/app/Dialog.html#openContextMenu(android.view.View)(https://developer.android.com/reference/android/view/View.html view)` `void` `https://developer.android.com/reference/android/app/Dialog.html#openOptionsMenu()()` `void` `https://developer.android.com/reference/android/app/Dialog.html#registerForContextMenu(android.view.View)(https://developer.android.com/reference/android/view/View.html view)` `final boolean` `https://developer.android.com/reference/android/app/Dialog.html#requestWindowFeature(int)(int featureId)` `final T` `<T extends https://developer.android.com/reference/android/view/View.html> https://developer.android.com/reference/android/app/Dialog.html#requireViewById(int)(int id)` `void` `https://developer.android.com/reference/android/app/Dialog.html#setCancelMessage(android.os.Message)(https://developer.android.com/reference/android/os/Message.html msg)` `void` `https://developer.android.com/reference/android/app/Dialog.html#setCancelable(boolean)(boolean flag)` `void` `https://developer.android.com/reference/android/app/Dialog.html#setCanceledOnTouchOutside(boolean)(boolean cancel)` `void` `https://developer.android.com/reference/android/app/Dialog.html#setContentView(android.view.View)(https://developer.android.com/reference/android/view/View.html view)` `void` `https://developer.android.com/reference/android/app/Dialog.html#setDismissMessage(android.os.Message)(https://developer.android.com/reference/android/os/Message.html msg)` `final void` `https://developer.android.com/reference/android/app/Dialog.html#setFeatureDrawable(int, android.graphics.drawable.Drawable)(int featureId, https://developer.android.com/reference/android/graphics/drawable/Drawable.html drawable)` `final void` `https://developer.android.com/reference/android/app/Dialog.html#setFeatureDrawableAlpha(int, int)(int featureId, int alpha)` `final void` `https://developer.android.com/reference/android/app/Dialog.html#setFeatureDrawableResource(int, int)(int featureId, int resId)` `final void` `https://developer.android.com/reference/android/app/Dialog.html#setFeatureDrawableUri(int, android.net.Uri)(int featureId, https://developer.android.com/reference/android/net/Uri.html uri)` `void` `https://developer.android.com/reference/android/app/Dialog.html#setOnCancelListener(android.content.DialogInterface.OnCancelListener)(https://developer.android.com/reference/android/content/DialogInterface.OnCancelListener.html listener)` `void` `https://developer.android.com/reference/android/app/Dialog.html#setOnDismissListener(android.content.DialogInterface.OnDismissListener)(https://developer.android.com/reference/android/content/DialogInterface.OnDismissListener.html listener)` `void` `https://developer.android.com/reference/android/app/Dialog.html#setOnKeyListener(android.content.DialogInterface.OnKeyListener)(https://developer.android.com/reference/android/content/DialogInterface.OnKeyListener.html onKeyListener)` `void` `https://developer.android.com/reference/android/app/Dialog.html#setOnShowListener(android.content.DialogInterface.OnShowListener)(https://developer.android.com/reference/android/content/DialogInterface.OnShowListener.html listener)` `final void` `https://developer.android.com/reference/android/app/Dialog.html#setOwnerActivity(android.app.Activity)(https://developer.android.com/reference/android/app/Activity.html activity)` `void` `https://developer.android.com/reference/android/app/Dialog.html#setTitle(int)(int titleId)` `final void` `https://developer.android.com/reference/android/app/Dialog.html#setVolumeControlStream(int)(int streamType)` `void` `https://developer.android.com/reference/android/app/Dialog.html#show()()` `void` `https://developer.android.com/reference/android/app/Dialog.html#takeKeyEvents(boolean)(boolean get)` `void` `https://developer.android.com/reference/android/app/Dialog.html#unregisterForContextMenu(android.view.View)(https://developer.android.com/reference/android/view/View.html view)` From [android.content.DialogInterface](https://developer.android.com/reference/android/content/DialogInterface.html) `abstract void` `https://developer.android.com/reference/android/content/DialogInterface.html#cancel()()` `abstract void` `https://developer.android.com/reference/android/content/DialogInterface.html#dismiss()()` From [androidx.lifecycle.LifecycleOwner](https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner) `abstract https://developer.android.com/reference/androidx/lifecycle/Lifecycle` `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner#getLifecycle()()`

The `https://developer.android.com/reference/androidx/lifecycle/Lifecycle` of this owner.
From [androidx.navigationevent.NavigationEventDispatcherOwner](https://developer.android.com/reference/androidx/navigationevent/NavigationEventDispatcherOwner) `abstract https://developer.android.com/reference/androidx/navigationevent/NavigationEventDispatcher` `https://developer.android.com/reference/androidx/navigationevent/NavigationEventDispatcherOwner#getNavigationEventDispatcher()()`

The `https://developer.android.com/reference/androidx/navigationevent/NavigationEventDispatcher` that should handle the navigation events.
From [androidx.activity.OnBackPressedDispatcherOwner](https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcherOwner) `abstract https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcher` `https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcherOwner#getOnBackPressedDispatcher()()`

The `https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcher` that should handle the system back button.
From [androidx.savedstate.SavedStateRegistryOwner](https://developer.android.com/reference/androidx/savedstate/SavedStateRegistryOwner) `abstract https://developer.android.com/reference/androidx/savedstate/SavedStateRegistry` `https://developer.android.com/reference/androidx/savedstate/SavedStateRegistryOwner#getSavedStateRegistry()()`

The `https://developer.android.com/reference/androidx/savedstate/SavedStateRegistry` owned by this `https://developer.android.com/reference/androidx/savedstate/SavedStateRegistryOwner`.
From [android.view.Window.Callback](https://developer.android.com/reference/android/view/Window.Callback.html) `void` `https://developer.android.com/reference/android/view/Window.Callback.html#onPointerCaptureChanged(boolean)(boolean hasCapture)` `void` `https://developer.android.com/reference/android/view/Window.Callback.html#onProvideKeyboardShortcuts(java.util.List&lt;android.view.KeyboardShortcutGroup&gt;, android.view.Menu, int)(
https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/android/view/KeyboardShortcutGroup.html> data,
https://developer.android.com/reference/android/view/Menu.html menu,
int deviceId
)`

## Protected constructors

### AlertDialog

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
protected AlertDialog(@NonNull Context context)
```

### AlertDialog

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
protected AlertDialog(@NonNull Context context, @StyleRes int themeResId)
```

Construct an AlertDialog that uses an explicit theme. The actual style that an AlertDialog uses is a private implementation, however you can here supply either the name of an attribute in the theme from which to get the dialog's style (such as `https://developer.android.com/reference/androidx/appcompat/R.attr#alertDialogTheme()`.

### AlertDialog

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
protected AlertDialog(
    @NonNull Context context,
    boolean cancelable,
    @Nullable DialogInterface.OnCancelListener cancelListener
)
```

## Public methods

### getButton

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
public Button getButton(int whichButton)
```

Gets one of the buttons used in the dialog. Returns null if the specified button does not exist or the dialog has not yet been fully created (for example, via `https://developer.android.com/reference/android/app/Dialog.html#show()` or `https://developer.android.com/reference/android/app/Dialog.html#create()`).

| Parameters |
|---|---|
| `int whichButton` | The identifier of the button that should be returned. For example, this can be `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON_POSITIVE`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/widget/Button.html` | The button from the dialog, or null if a button does not exist. |

### getListView

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
public ListView getListView()
```

Gets the list view used in the dialog.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/widget/ListView.html` | The `https://developer.android.com/reference/android/widget/ListView.html` from the dialog. |

### onKeyDown

```
public boolean onKeyDown(int keyCode, KeyEvent event)
```

### onKeyUp

```
public boolean onKeyUp(int keyCode, KeyEvent event)
```

### setButton

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
public void setButton(
    int whichButton,
    CharSequence text,
    DialogInterface.OnClickListener listener
)
```

Sets a listener to be invoked when the positive button of the dialog is pressed. This method has no effect if called after `https://developer.android.com/reference/android/app/Dialog.html#show()`.

| Parameters |
|---|---|
| `int whichButton` | Which button to set the listener on, can be one of `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON_POSITIVE`, `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON_NEGATIVE`, or `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON_NEUTRAL` |
| `https://developer.android.com/reference/java/lang/CharSequence.html text` | The text to display in positive button. |
| `https://developer.android.com/reference/android/content/DialogInterface.OnClickListener.html listener` | The `https://developer.android.com/reference/android/content/DialogInterface.OnClickListener.html` to use. |

### setButton

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
public void setButton(int whichButton, CharSequence text, Message msg)
```

Sets a message to be sent when a button is pressed. This method has no effect if called after `https://developer.android.com/reference/android/app/Dialog.html#show()`.

| Parameters |
|---|---|
| `int whichButton` | Which button to set the message for, can be one of `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON_POSITIVE`, `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON_NEGATIVE`, or `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON_NEUTRAL` |
| `https://developer.android.com/reference/java/lang/CharSequence.html text` | The text to display in positive button. |
| `https://developer.android.com/reference/android/os/Message.html msg` | The `https://developer.android.com/reference/android/os/Message.html` to be sent when clicked. |

### setButton

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
public void setButton(
    int whichButton,
    CharSequence text,
    Drawable icon,
    DialogInterface.OnClickListener listener
)
```

Sets an icon to be displayed along with the button text and a listener to be invoked when the positive button of the dialog is pressed. This method has no effect if called after `https://developer.android.com/reference/android/app/Dialog.html#show()`.

| Parameters |
|---|---|
| `int whichButton` | Which button to set the listener on, can be one of `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON_POSITIVE`, `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON_NEGATIVE`, or `https://developer.android.com/reference/android/content/DialogInterface.html#BUTTON_NEUTRAL` |
| `https://developer.android.com/reference/java/lang/CharSequence.html text` | The text to display in positive button. |
| `https://developer.android.com/reference/android/graphics/drawable/Drawable.html icon` | The `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` to be set as an icon for the button. |
| `https://developer.android.com/reference/android/content/DialogInterface.OnClickListener.html listener` | The `https://developer.android.com/reference/android/content/DialogInterface.OnClickListener.html` to use. |

### setCustomTitle

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
public void setCustomTitle(View customTitleView)
```

This method has no effect if called after `https://developer.android.com/reference/android/app/Dialog.html#show()`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appcompat/app/AlertDialog.Builder#setCustomTitle(android.view.View)` |   |

### setIcon

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
public void setIcon(Drawable icon)
```

Set the `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` to be used in the title.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Drawable.html icon` | Drawable to use as the icon or null if you don't want an icon. |

### setIcon

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
public void setIcon(int resId)
```

Set resId to 0 if you don't want an icon.

| Parameters |
|---|---|
| `int resId` | the resourceId of the drawable to use as the icon or 0 if you don't want an icon. |

### setIconAttribute

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
public void setIconAttribute(int attrId)
```

Sets an icon as supplied by a theme attribute. e.g. android.R.attr.alertDialogIcon

| Parameters |
|---|---|
| `int attrId` | ID of a theme attribute that points to a drawable resource. |

### setMessage

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
public void setMessage(CharSequence message)
```

Sets the message to display.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence.html message` | The message to display in the dialog. |

### setTitle

```
public void setTitle(CharSequence title)
```

### setView

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
public void setView(View view)
```

Set the view to display in the dialog. This method has no effect if called after `https://developer.android.com/reference/android/app/Dialog.html#show()`.

### setView

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appcompat#1.1.0)

```
public void setView(
    View view,
    int viewSpacingLeft,
    int viewSpacingTop,
    int viewSpacingRight,
    int viewSpacingBottom
)
```

Set the view to display in the dialog, specifying the spacing to appear around that view. This method has no effect if called after `https://developer.android.com/reference/android/app/Dialog.html#show()`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/view/View.html view` | The view to show in the content area of the dialog |
| `int viewSpacingLeft` | Extra space to appear to the left of `view` |
| `int viewSpacingTop` | Extra space to appear above `view` |
| `int viewSpacingRight` | Extra space to appear to the right of `view` |
| `int viewSpacingBottom` | Extra space to appear below `view` |

## Protected methods

### onCreate

```
protected void onCreate(Bundle savedInstanceState)
```