AlertDialogpublic class AlertDialog extends Dialog implements android.content.DialogInterfaceA 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 = (FrameLayout) findViewById(android.R.id.custom);
fl.addView(myView, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
The AlertDialog class takes care of automatically setting
{@link WindowManager.LayoutParams#FLAG_ALT_FOCUSABLE_IM
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM} for you based on whether
any views in the dialog return true from {@link View#onCheckIsTextEditor()
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 {@link #onCreate}.
Developer Guides
For more information about creating dialogs, read the
Dialogs developer guide.
|
Fields Summary |
---|
private com.android.internal.app.AlertController | mAlert | public static final int | THEME_TRADITIONALSpecial theme constant for {@link #AlertDialog(Context, int)}: use
the traditional (pre-Holo) alert dialog theme. | public static final int | THEME_HOLO_DARKSpecial theme constant for {@link #AlertDialog(Context, int)}: use
the holographic alert theme with a dark background. | public static final int | THEME_HOLO_LIGHTSpecial theme constant for {@link #AlertDialog(Context, int)}: use
the holographic alert theme with a light background. | public static final int | THEME_DEVICE_DEFAULT_DARKSpecial theme constant for {@link #AlertDialog(Context, int)}: use
the device's default alert theme with a dark background. | public static final int | THEME_DEVICE_DEFAULT_LIGHTSpecial theme constant for {@link #AlertDialog(Context, int)}: use
the device's default alert theme with a light background. | public static final int | LAYOUT_HINT_NONENo layout hint. | public static final int | LAYOUT_HINT_SIDEHint layout to the side. |
Constructors Summary |
---|
protected AlertDialog(android.content.Context context)
this(context, resolveDialogTheme(context, 0), true);
| protected AlertDialog(android.content.Context context, int theme)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 {@link android.R.attr#alertDialogTheme}
or one of the constants {@link #THEME_TRADITIONAL},
{@link #THEME_HOLO_DARK}, or {@link #THEME_HOLO_LIGHT}.
this(context, theme, true);
| AlertDialog(android.content.Context context, int theme, boolean createThemeContextWrapper)
super(context, resolveDialogTheme(context, theme), createThemeContextWrapper);
mWindow.alwaysReadCloseOnTouchAttr();
mAlert = new AlertController(getContext(), this, getWindow());
| protected AlertDialog(android.content.Context context, boolean cancelable, OnCancelListener cancelListener)
super(context, resolveDialogTheme(context, 0));
mWindow.alwaysReadCloseOnTouchAttr();
setCancelable(cancelable);
setOnCancelListener(cancelListener);
mAlert = new AlertController(context, this, getWindow());
|
Methods Summary |
---|
public android.widget.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 {@link #show()} or {@link #create()}).
return mAlert.getButton(whichButton);
| public android.widget.ListView | getListView()Gets the list view used in the dialog.
return mAlert.getListView();
| protected void | onCreate(android.os.Bundle savedInstanceState)
super.onCreate(savedInstanceState);
mAlert.installContent();
| public boolean | onKeyDown(int keyCode, android.view.KeyEvent event)
if (mAlert.onKeyDown(keyCode, event)) return true;
return super.onKeyDown(keyCode, event);
| public boolean | onKeyUp(int keyCode, android.view.KeyEvent event)
if (mAlert.onKeyUp(keyCode, event)) return true;
return super.onKeyUp(keyCode, event);
| static int | resolveDialogTheme(android.content.Context context, int resid)
if (resid == THEME_TRADITIONAL) {
return com.android.internal.R.style.Theme_Dialog_Alert;
} else if (resid == THEME_HOLO_DARK) {
return com.android.internal.R.style.Theme_Holo_Dialog_Alert;
} else if (resid == THEME_HOLO_LIGHT) {
return com.android.internal.R.style.Theme_Holo_Light_Dialog_Alert;
} else if (resid == THEME_DEVICE_DEFAULT_DARK) {
return com.android.internal.R.style.Theme_DeviceDefault_Dialog_Alert;
} else if (resid == THEME_DEVICE_DEFAULT_LIGHT) {
return com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog_Alert;
} else if (resid >= 0x01000000) { // start of real resource IDs.
return resid;
} else {
TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(com.android.internal.R.attr.alertDialogTheme,
outValue, true);
return outValue.resourceId;
}
| public void | setButton(int whichButton, java.lang.CharSequence text, android.os.Message msg)Set a message to be sent when a button is pressed.
mAlert.setButton(whichButton, text, null, msg);
| public void | setButton(int whichButton, java.lang.CharSequence text, OnClickListener listener)Set a listener to be invoked when the positive button of the dialog is pressed.
mAlert.setButton(whichButton, text, listener, null);
| public void | setButton(java.lang.CharSequence text, android.os.Message msg)
setButton(BUTTON_POSITIVE, text, msg);
| public void | setButton(java.lang.CharSequence text, OnClickListener listener)Set a listener to be invoked when button 1 of the dialog is pressed.
setButton(BUTTON_POSITIVE, text, listener);
| public void | setButton2(java.lang.CharSequence text, android.os.Message msg)
setButton(BUTTON_NEGATIVE, text, msg);
| public void | setButton2(java.lang.CharSequence text, OnClickListener listener)Set a listener to be invoked when button 2 of the dialog is pressed.
setButton(BUTTON_NEGATIVE, text, listener);
| public void | setButton3(java.lang.CharSequence text, android.os.Message msg)
setButton(BUTTON_NEUTRAL, text, msg);
| public void | setButton3(java.lang.CharSequence text, OnClickListener listener)Set a listener to be invoked when button 3 of the dialog is pressed.
setButton(BUTTON_NEUTRAL, text, listener);
| void | setButtonPanelLayoutHint(int layoutHint)Internal api to allow hinting for the best button panel layout.
mAlert.setButtonPanelLayoutHint(layoutHint);
| public void | setCustomTitle(android.view.View customTitleView)
mAlert.setCustomTitle(customTitleView);
| public void | setIcon(int resId)Set resId to 0 if you don't want an icon.
mAlert.setIcon(resId);
| public void | setIcon(android.graphics.drawable.Drawable icon)
mAlert.setIcon(icon);
| public void | setIconAttribute(int attrId)Set an icon as supplied by a theme attribute. e.g. android.R.attr.alertDialogIcon
TypedValue out = new TypedValue();
mContext.getTheme().resolveAttribute(attrId, out, true);
mAlert.setIcon(out.resourceId);
| public void | setInverseBackgroundForced(boolean forceInverseBackground)
mAlert.setInverseBackgroundForced(forceInverseBackground);
| public void | setMessage(java.lang.CharSequence message)
mAlert.setMessage(message);
| public void | setTitle(java.lang.CharSequence title)
super.setTitle(title);
mAlert.setTitle(title);
| public void | setView(android.view.View view)Set the view to display in that dialog.
mAlert.setView(view);
| public void | setView(android.view.View view, int viewSpacingLeft, int viewSpacingTop, int viewSpacingRight, int viewSpacingBottom)Set the view to display in that dialog, specifying the spacing to appear around that
view.
mAlert.setView(view, viewSpacingLeft, viewSpacingTop, viewSpacingRight, viewSpacingBottom);
|
|