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)
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.

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

Sets a listener to be invoked when the positive button of the dialog is pressed.

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

Sets a message to be sent when a button is pressed.

void setCustomTitle(View customTitleView)

This method has no effect if called after show().

void setIcon(Drawable icon)

Set the Drawable to be used in the title.

void setIcon(int resId)

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

void setIconAttribute(int attrId)

Sets an icon as supplied by a theme attribute.

void setMessage(CharSequence message)

Sets the message to display.

void setTitle(CharSequence title)
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.

void setView(View view)

Set the view to display in the dialog.

Protected methods

void onCreate(Bundle savedInstanceState)

Inherited methods

From class
From class