AlertDialog

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

Types

Link copied to clipboard
open class Builder

Functions

Link copied to clipboard
open fun getButton(whichButton: Int): Button
Gets one of the buttons used in the dialog.
Link copied to clipboard
open fun getListView(): ListView
Gets the list view used in the dialog.
Link copied to clipboard
open fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean
Link copied to clipboard
open fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean
Link copied to clipboard
open fun setButton(whichButton: Int, text: CharSequence, listener: DialogInterface.OnClickListener)
Sets a listener to be invoked when the positive button of the dialog is pressed.
open fun setButton(whichButton: Int, text: CharSequence, msg: Message)
Sets a message to be sent when a button is pressed.
open fun setButton(whichButton: Int, text: CharSequence, icon: Drawable, listener: DialogInterface.OnClickListener)
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.
Link copied to clipboard
open fun setCustomTitle(customTitleView: View)
This method has no effect if called after show.
Link copied to clipboard
open fun setIcon(icon: Drawable)
Set the Drawable to be used in the title.
open fun setIcon(resId: Int)
Set resId to 0 if you don't want an icon.
Link copied to clipboard
open fun setIconAttribute(attrId: Int)
Sets an icon as supplied by a theme attribute.
Link copied to clipboard
open fun setMessage(message: CharSequence)
Sets the message to display.
Link copied to clipboard
open fun setTitle(title: CharSequence)
Link copied to clipboard
open fun setView(view: View)
Set the view to display in the dialog.
open fun setView(view: View, viewSpacingLeft: Int, viewSpacingTop: Int, viewSpacingRight: Int, viewSpacingBottom: Int)
Set the view to display in the dialog, specifying the spacing to appear around that view.