added in version 24.1.0
belongs to Maven artifact


public class AlertDialog
extends AppCompatDialog implements DialogInterface

Known Direct Subclasses

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(;
 fl.addView(myView, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));

The AlertDialog class takes care of automatically setting android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM for you based on whether any views in the dialog return true from View.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 onCreate(Bundle).

Developer Guides

For more information about creating dialogs, read the Dialogs developer guide.


Nested classes

class AlertDialog.Builder


Inherited constants

From interface android.content.DialogInterface

Protected constructors

AlertDialog(Context context)
AlertDialog(Context context, int themeResId)

Construct an AlertDialog that uses an explicit theme.

AlertDialog(Context context, boolean cancelable, DialogInterface.OnCancelListener cancelListener)

Public methods

Button getButton(int whichButton)

Gets one of the buttons used in the dialog.

ListView getListView()

Gets the list view used in the dialog.

boolean onKeyDown(int keyCode, KeyEvent event)
boolean onKeyUp(int keyCode, KeyEvent event)