FileDocCategorySizeDatePackage
Dialog.javaAPI DocAndroid 5.1 API41857Thu Mar 12 22:22:10 GMT 2015android.app

Dialog

public class Dialog extends Object implements Window.OnWindowDismissedCallback, android.content.DialogInterface, Window.Callback, android.view.View.OnCreateContextMenuListener, KeyEvent.Callback
Base class for Dialogs.

Note: Activities provide a facility to manage the creation, saving and restoring of dialogs. See {@link Activity#onCreateDialog(int)}, {@link Activity#onPrepareDialog(int, Dialog)}, {@link Activity#showDialog(int)}, and {@link Activity#dismissDialog(int)}. If these methods are used, {@link #getOwnerActivity()} will return the Activity that managed this dialog.

Often you will want to have a Dialog display on top of the current input method, because there is no reason for it to accept text. You can do this by setting the {@link WindowManager.LayoutParams#FLAG_ALT_FOCUSABLE_IM WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM} window flag (assuming your Dialog takes input focus, as it the default) with the following code:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

Developer Guides

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

Fields Summary
private static final String
TAG
private Activity
mOwnerActivity
final android.content.Context
mContext
final android.view.WindowManager
mWindowManager
android.view.Window
mWindow
android.view.View
mDecor
private ActionBar
mActionBar
protected boolean
mCancelable
This field should be made private, so it is hidden from the SDK. {@hide}
private String
mCancelAndDismissTaken
private android.os.Message
mCancelMessage
private android.os.Message
mDismissMessage
private android.os.Message
mShowMessage
private OnKeyListener
mOnKeyListener
private boolean
mCreated
private boolean
mShowing
private boolean
mCanceled
private final android.os.Handler
mHandler
private static final int
DISMISS
private static final int
CANCEL
private static final int
SHOW
private android.os.Handler
mListenersHandler
private android.view.ActionMode
mActionMode
private final Runnable
mDismissAction
private static final String
DIALOG_SHOWING_TAG
private static final String
DIALOG_HIERARCHY_TAG
Constructors Summary
public Dialog(android.content.Context context)
Create a Dialog window that uses the default dialog frame style.

param
context The Context the Dialog is to run it. In particular, it uses the window manager and theme in this context to present its UI.


                                                                              
       
        this(context, 0, true);
    
public Dialog(android.content.Context context, int theme)
Create a Dialog window that uses a custom dialog style.

param
context The Context in which the Dialog should run. In particular, it uses the window manager and theme from this context to present its UI.
param
theme A style resource describing the theme to use for the window. See Style and Theme Resources for more information about defining and using styles. This theme is applied on top of the current theme in context. If 0, the default dialog theme will be used.

        this(context, theme, true);
    
Dialog(android.content.Context context, int theme, boolean createContextThemeWrapper)

        if (createContextThemeWrapper) {
            if (theme == 0) {
                TypedValue outValue = new TypedValue();
                context.getTheme().resolveAttribute(com.android.internal.R.attr.dialogTheme,
                        outValue, true);
                theme = outValue.resourceId;
            }
            mContext = new ContextThemeWrapper(context, theme);
        } else {
            mContext = context;
        }

        mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
        Window w = PolicyManager.makeNewWindow(mContext);
        mWindow = w;
        w.setCallback(this);
        w.setOnWindowDismissedCallback(this);
        w.setWindowManager(mWindowManager, null, null);
        w.setGravity(Gravity.CENTER);
        mListenersHandler = new ListenersHandler(this);
    
protected Dialog(android.content.Context context, boolean cancelable, android.os.Message cancelCallback)

deprecated
hide

        this(context);
        mCancelable = cancelable;
        mCancelMessage = cancelCallback;
    
protected Dialog(android.content.Context context, boolean cancelable, OnCancelListener cancelListener)

        this(context);
        mCancelable = cancelable;
        setOnCancelListener(cancelListener);
    
Methods Summary
public voidaddContentView(android.view.View view, android.view.ViewGroup.LayoutParams params)
Add an additional content view to the screen. Added after any existing ones in the screen -- existing views are NOT removed.

param
view The desired content to display.
param
params Layout parameters for the view.

        mWindow.addContentView(view, params);
    
public voidcancel()
Cancel the dialog. This is essentially the same as calling {@link #dismiss()}, but it will also call your {@link DialogInterface.OnCancelListener} (if registered).

        if (!mCanceled && mCancelMessage != null) {
            mCanceled = true;
            // Obtain a new message so this dialog can be re-used
            Message.obtain(mCancelMessage).sendToTarget();
        }
        dismiss();
    
public voidcloseOptionsMenu()

see
Activity#closeOptionsMenu()

        if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL)) {
            mWindow.closePanel(Window.FEATURE_OPTIONS_PANEL);
        }
    
public voidcreate()
Forces immediate creation of the dialog.

Note that you should not override this method to perform dialog creation. Rather, override {@link #onCreate(Bundle)}.

        if (!mCreated) {
            dispatchOnCreate(null);
        }
    
public voiddismiss()
Dismiss this dialog, removing it from the screen. This method can be invoked safely from any thread. Note that you should not override this method to do cleanup when the dialog is dismissed, instead implement that in {@link #onStop}.

        if (Looper.myLooper() == mHandler.getLooper()) {
            dismissDialog();
        } else {
            mHandler.post(mDismissAction);
        }
    
voiddismissDialog()

        if (mDecor == null || !mShowing) {
            return;
        }

        if (mWindow.isDestroyed()) {
            Log.e(TAG, "Tried to dismissDialog() but the Dialog's window was already destroyed!");
            return;
        }

        try {
            mWindowManager.removeViewImmediate(mDecor);
        } finally {
            if (mActionMode != null) {
                mActionMode.finish();
            }
            mDecor = null;
            mWindow.closeAllPanels();
            onStop();
            mShowing = false;

            sendDismissMessage();
        }
    
public booleandispatchGenericMotionEvent(android.view.MotionEvent ev)
Called to process generic motion events. You can override this to intercept all generic motion events before they are dispatched to the window. Be sure to call this implementation for generic motion events that should be handled normally.

param
ev The generic motion event.
return
boolean Return true if this event was consumed.

        if (mWindow.superDispatchGenericMotionEvent(ev)) {
            return true;
        }
        return onGenericMotionEvent(ev);
    
public booleandispatchKeyEvent(android.view.KeyEvent event)
Called to process key events. You can override this to intercept all key events before they are dispatched to the window. Be sure to call this implementation for key events that should be handled normally.

param
event The key event.
return
boolean Return true if this event was consumed.

        if ((mOnKeyListener != null) && (mOnKeyListener.onKey(this, event.getKeyCode(), event))) {
            return true;
        }
        if (mWindow.superDispatchKeyEvent(event)) {
            return true;
        }
        return event.dispatch(this, mDecor != null
                ? mDecor.getKeyDispatcherState() : null, this);
    
public booleandispatchKeyShortcutEvent(android.view.KeyEvent event)
Called to process a key shortcut event. You can override this to intercept all key shortcut events before they are dispatched to the window. Be sure to call this implementation for key shortcut events that should be handled normally.

param
event The key shortcut event.
return
True if this event was consumed.

        if (mWindow.superDispatchKeyShortcutEvent(event)) {
            return true;
        }
        return onKeyShortcut(event.getKeyCode(), event);
    
voiddispatchOnCreate(android.os.Bundle savedInstanceState)

        if (!mCreated) {
            onCreate(savedInstanceState);
            mCreated = true;
        }
    
public booleandispatchPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)

        event.setClassName(getClass().getName());
        event.setPackageName(mContext.getPackageName());

        LayoutParams params = getWindow().getAttributes();
        boolean isFullScreen = (params.width == LayoutParams.MATCH_PARENT) &&
            (params.height == LayoutParams.MATCH_PARENT);
        event.setFullScreen(isFullScreen);

        return false;
    
public booleandispatchTouchEvent(android.view.MotionEvent ev)
Called to process touch screen events. You can override this to intercept all touch screen events before they are dispatched to the window. Be sure to call this implementation for touch screen events that should be handled normally.

param
ev The touch screen event.
return
boolean Return true if this event was consumed.

        if (mWindow.superDispatchTouchEvent(ev)) {
            return true;
        }
        return onTouchEvent(ev);
    
public booleandispatchTrackballEvent(android.view.MotionEvent ev)
Called to process trackball events. You can override this to intercept all trackball events before they are dispatched to the window. Be sure to call this implementation for trackball events that should be handled normally.

param
ev The trackball event.
return
boolean Return true if this event was consumed.

        if (mWindow.superDispatchTrackballEvent(ev)) {
            return true;
        }
        return onTrackballEvent(ev);
    
public android.view.ViewfindViewById(int id)
Finds a child view with the given identifier. Returns null if the specified child view does not exist or the dialog has not yet been fully created (for example, via {@link #show()} or {@link #create()}).

param
id the identifier of the view to find
return
The view with the given id or null.

        return mWindow.findViewById(id);
    
public ActionBargetActionBar()
Retrieve the {@link ActionBar} attached to this dialog, if present.

return
The ActionBar attached to the dialog or null if no ActionBar is present.

        return mActionBar;
    
private android.content.ComponentNamegetAssociatedActivity()

return
The activity associated with this dialog, or null if there is no associated activity.

        Activity activity = mOwnerActivity;
        Context context = getContext();
        while (activity == null && context != null) {
            if (context instanceof Activity) {
                activity = (Activity) context;  // found it!
            } else {
                context = (context instanceof ContextWrapper) ?
                        ((ContextWrapper) context).getBaseContext() : // unwrap one level
                        null;                                         // done
            }
        }
        return activity == null ? null : activity.getComponentName();
    
public final android.content.ContextgetContext()
Retrieve the Context this Dialog is running in.

return
Context The Context used by the Dialog.

        return mContext;
    
public android.view.ViewgetCurrentFocus()
Call {@link android.view.Window#getCurrentFocus} on the Window if this Activity to return the currently focused view.

return
View The current View with focus or null.
see
#getWindow
see
android.view.Window#getCurrentFocus

        return mWindow != null ? mWindow.getCurrentFocus() : null;
    
public android.view.LayoutInflatergetLayoutInflater()

        return getWindow().getLayoutInflater();
    
public final ActivitygetOwnerActivity()
Returns the Activity that owns this Dialog. For example, if {@link Activity#showDialog(int)} is used to show this Dialog, that Activity will be the owner (by default). Depending on how this dialog was created, this may return null.

return
The Activity that owns this Dialog.

        return mOwnerActivity;
    
public final intgetVolumeControlStream()

see
Activity#getVolumeControlStream()

        return getWindow().getVolumeControlStream();
    
public android.view.WindowgetWindow()
Retrieve the current Window for the activity. This can be used to directly access parts of the Window API that are not available through Activity/Screen.

return
Window The current window, or null if the activity is not visual.

        return mWindow;
    
public voidhide()
Hide the dialog, but do not dismiss it.

        if (mDecor != null) {
            mDecor.setVisibility(View.GONE);
        }
    
public voidinvalidateOptionsMenu()

see
Activity#invalidateOptionsMenu()

        if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL)) {
            mWindow.invalidatePanelMenu(Window.FEATURE_OPTIONS_PANEL);
        }
    
public booleanisShowing()

return
Whether the dialog is currently showing.

        return mShowing;
    
public voidonActionModeFinished(android.view.ActionMode mode)
{@inheritDoc} Note that if you override this method you should always call through to the superclass implementation by calling super.onActionModeFinished(mode).

        if (mode == mActionMode) {
            mActionMode = null;
        }
    
public voidonActionModeStarted(android.view.ActionMode mode)
{@inheritDoc} Note that if you override this method you should always call through to the superclass implementation by calling super.onActionModeStarted(mode).

        mActionMode = mode;
    
public voidonAttachedToWindow()

    
public voidonBackPressed()
Called when the dialog has detected the user's press of the back key. The default implementation simply cancels the dialog (only if it is cancelable), but you can override this to do whatever you want.

        if (mCancelable) {
            cancel();
        }
    
public voidonContentChanged()

    
public booleanonContextItemSelected(android.view.MenuItem item)

see
Activity#onContextItemSelected(MenuItem)

        return false;
    
public voidonContextMenuClosed(android.view.Menu menu)

see
Activity#onContextMenuClosed(Menu)

    
protected voidonCreate(android.os.Bundle savedInstanceState)
Similar to {@link Activity#onCreate}, you should initialize your dialog in this method, including calling {@link #setContentView}.

param
savedInstanceState If this dialog is being reinitalized after a the hosting activity was previously shut down, holds the result from the most recent call to {@link #onSaveInstanceState}, or null if this is the first time.

    
public voidonCreateContextMenu(android.view.ContextMenu menu, android.view.View v, android.view.ContextMenu.ContextMenuInfo menuInfo)

see
Activity#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)

    
public booleanonCreateOptionsMenu(android.view.Menu menu)
It is usually safe to proxy this call to the owner activity's {@link Activity#onCreateOptionsMenu(Menu)} if the client desires the same menu for this Dialog.

see
Activity#onCreateOptionsMenu(Menu)
see
#getOwnerActivity()

        return true;
    
public booleanonCreatePanelMenu(int featureId, android.view.Menu menu)

see
Activity#onCreatePanelMenu(int, Menu)

        if (featureId == Window.FEATURE_OPTIONS_PANEL) {
            return onCreateOptionsMenu(menu);
        }
        
        return false;
    
public android.view.ViewonCreatePanelView(int featureId)

see
Activity#onCreatePanelView(int)

        return null;
    
public voidonDetachedFromWindow()

    
public booleanonGenericMotionEvent(android.view.MotionEvent event)
Called when a generic motion event was not handled by any of the views inside of the dialog.

Generic motion events describe joystick movements, mouse hovers, track pad touches, scroll wheel movements and other input events. The {@link MotionEvent#getSource() source} of the motion event specifies the class of input that was received. Implementations of this method must examine the bits in the source before processing the event. The following code example shows how this is done.

Generic motion events with source class {@link android.view.InputDevice#SOURCE_CLASS_POINTER} are delivered to the view under the pointer. All other generic motion events are delivered to the focused view.

See {@link View#onGenericMotionEvent(MotionEvent)} for an example of how to handle this event.

param
event The generic motion event being processed.
return
Return true if you have consumed the event, false if you haven't. The default implementation always returns false.

        return false;
    
public booleanonKeyDown(int keyCode, android.view.KeyEvent event)
A key was pressed down.

If the focused view didn't want this event, this method is called.

The default implementation consumed the KEYCODE_BACK to later handle it in {@link #onKeyUp}.

see
#onKeyUp
see
android.view.KeyEvent

        if (keyCode == KeyEvent.KEYCODE_BACK) {
            event.startTracking();
            return true;
        }

        return false;
    
public booleanonKeyLongPress(int keyCode, android.view.KeyEvent event)
Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle the event).

        return false;
    
public booleanonKeyMultiple(int keyCode, int repeatCount, android.view.KeyEvent event)
Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle the event).

        return false;
    
public booleanonKeyShortcut(int keyCode, android.view.KeyEvent event)
Called when a key shortcut event is not handled by any of the views in the Dialog. Override this method to implement global key shortcuts for the Dialog. Key shortcuts can also be implemented by setting the {@link MenuItem#setShortcut(char, char) shortcut} property of menu items.

param
keyCode The value in event.getKeyCode().
param
event Description of the key event.
return
True if the key shortcut was handled.

        return false;
    
public booleanonKeyUp(int keyCode, android.view.KeyEvent event)
A key was released.

The default implementation handles KEYCODE_BACK to close the dialog.

see
#onKeyDown
see
KeyEvent

        if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking()
                && !event.isCanceled()) {
            onBackPressed();
            return true;
        }
        return false;
    
public booleanonMenuItemSelected(int featureId, android.view.MenuItem item)

see
Activity#onMenuItemSelected(int, MenuItem)

        return false;
    
public booleanonMenuOpened(int featureId, android.view.Menu menu)

see
Activity#onMenuOpened(int, Menu)

        if (featureId == Window.FEATURE_ACTION_BAR) {
            mActionBar.dispatchMenuVisibilityChanged(true);
        }
        return true;
    
public booleanonOptionsItemSelected(android.view.MenuItem item)

see
Activity#onOptionsItemSelected(MenuItem)

        return false;
    
public voidonOptionsMenuClosed(android.view.Menu menu)

see
Activity#onOptionsMenuClosed(Menu)

    
public voidonPanelClosed(int featureId, android.view.Menu menu)

see
Activity#onPanelClosed(int, Menu)

        if (featureId == Window.FEATURE_ACTION_BAR) {
            mActionBar.dispatchMenuVisibilityChanged(false);
        }
    
public booleanonPrepareOptionsMenu(android.view.Menu menu)
It is usually safe to proxy this call to the owner activity's {@link Activity#onPrepareOptionsMenu(Menu)} if the client desires the same menu for this Dialog.

see
Activity#onPrepareOptionsMenu(Menu)
see
#getOwnerActivity()

        return true;
    
public booleanonPreparePanel(int featureId, android.view.View view, android.view.Menu menu)

see
Activity#onPreparePanel(int, View, Menu)

        if (featureId == Window.FEATURE_OPTIONS_PANEL && menu != null) {
            boolean goforit = onPrepareOptionsMenu(menu);
            return goforit && menu.hasVisibleItems();
        }
        return true;
    
public voidonRestoreInstanceState(android.os.Bundle savedInstanceState)
Restore the state of the dialog from a previously saved bundle. The default implementation restores the state of the dialog's view hierarchy that was saved in the default implementation of {@link #onSaveInstanceState()}, so be sure to call through to super when overriding unless you want to do all restoring of state yourself.

param
savedInstanceState The state of the dialog previously saved by {@link #onSaveInstanceState()}.

        final Bundle dialogHierarchyState = savedInstanceState.getBundle(DIALOG_HIERARCHY_TAG);
        if (dialogHierarchyState == null) {
            // dialog has never been shown, or onCreated, nothing to restore.
            return;
        }
        dispatchOnCreate(savedInstanceState);
        mWindow.restoreHierarchyState(dialogHierarchyState);
        if (savedInstanceState.getBoolean(DIALOG_SHOWING_TAG)) {
            show();
        }
    
public android.os.BundleonSaveInstanceState()
Saves the state of the dialog into a bundle. The default implementation saves the state of its view hierarchy, so you'll likely want to call through to super if you override this to save additional state.

return
A bundle with the state of the dialog.


                                                      
       
        Bundle bundle = new Bundle();
        bundle.putBoolean(DIALOG_SHOWING_TAG, mShowing);
        if (mCreated) {
            bundle.putBundle(DIALOG_HIERARCHY_TAG, mWindow.saveHierarchyState());
        }
        return bundle;
    
public booleanonSearchRequested()
This hook is called when the user signals the desire to start a search.

        final SearchManager searchManager = (SearchManager) mContext
                .getSystemService(Context.SEARCH_SERVICE);

        // associate search with owner activity
        final ComponentName appName = getAssociatedActivity();
        if (appName != null && searchManager.getSearchableInfo(appName) != null) {
            searchManager.startSearch(null, false, appName, null, false);
            dismiss();
            return true;
        } else {
            return false;
        }
    
protected voidonStart()
Called when the dialog is starting.

        if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(true);
    
protected voidonStop()
Called to tell you that you're stopping.

        if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(false);
    
public booleanonTouchEvent(android.view.MotionEvent event)
Called when a touch screen event was not handled by any of the views under it. This is most useful to process touch events that happen outside of your window bounds, where there is no view to receive it.

param
event The touch screen event being processed.
return
Return true if you have consumed the event, false if you haven't. The default implementation will cancel the dialog when a touch happens outside of the window bounds.

        if (mCancelable && mShowing && mWindow.shouldCloseOnTouch(mContext, event)) {
            cancel();
            return true;
        }
        
        return false;
    
public booleanonTrackballEvent(android.view.MotionEvent event)
Called when the trackball was moved and not handled by any of the views inside of the activity. So, for example, if the trackball moves while focus is on a button, you will receive a call here because buttons do not normally do anything with trackball events. The call here happens before trackball movements are converted to DPAD key events, which then get sent back to the view hierarchy, and will be processed at the point for things like focus navigation.

param
event The trackball event being processed.
return
Return true if you have consumed the event, false if you haven't. The default implementation always returns false.

        return false;
    
public voidonWindowAttributesChanged(WindowManager.LayoutParams params)

        if (mDecor != null) {
            mWindowManager.updateViewLayout(mDecor, params);
        }
    
public voidonWindowDismissed()

hide

        dismiss();
    
public voidonWindowFocusChanged(boolean hasFocus)

    
public android.view.ActionModeonWindowStartingActionMode(ActionMode.Callback callback)

        if (mActionBar != null) {
            return mActionBar.startActionMode(callback);
        }
        return null;
    
public voidopenContextMenu(android.view.View view)

see
Activity#openContextMenu(View)

        view.showContextMenu();
    
public voidopenOptionsMenu()

see
Activity#openOptionsMenu()

        if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL)) {
            mWindow.openPanel(Window.FEATURE_OPTIONS_PANEL, null);
        }
    
public voidregisterForContextMenu(android.view.View view)

see
Activity#registerForContextMenu(View)

        view.setOnCreateContextMenuListener(this);
    
public final booleanrequestWindowFeature(int featureId)
Enable extended window features. This is a convenience for calling {@link android.view.Window#requestFeature getWindow().requestFeature()}.

param
featureId The desired feature as defined in {@link android.view.Window}.
return
Returns true if the requested feature is supported and now enabled.
see
android.view.Window#requestFeature

        return getWindow().requestFeature(featureId);
    
private voidsendDismissMessage()

        if (mDismissMessage != null) {
            // Obtain a new message so this dialog can be re-used
            Message.obtain(mDismissMessage).sendToTarget();
        }
    
private voidsendShowMessage()

        if (mShowMessage != null) {
            // Obtain a new message so this dialog can be re-used
            Message.obtain(mShowMessage).sendToTarget();
        }
    
public voidsetCancelMessage(android.os.Message msg)
Set a message to be sent when the dialog is canceled.

param
msg The msg to send when the dialog is canceled.
see
#setOnCancelListener(android.content.DialogInterface.OnCancelListener)

        mCancelMessage = msg;
    
public voidsetCancelable(boolean flag)
Sets whether this dialog is cancelable with the {@link KeyEvent#KEYCODE_BACK BACK} key.

        mCancelable = flag;
    
public voidsetCanceledOnTouchOutside(boolean cancel)
Sets whether this dialog is canceled when touched outside the window's bounds. If setting to true, the dialog is set to be cancelable if not already set.

param
cancel Whether the dialog should be canceled when touched outside the window.

        if (cancel && !mCancelable) {
            mCancelable = true;
        }
        
        mWindow.setCloseOnTouchOutside(cancel);
    
public voidsetContentView(int layoutResID)
Set the screen content from a layout resource. The resource will be inflated, adding all top-level views to the screen.

param
layoutResID Resource ID to be inflated.

        mWindow.setContentView(layoutResID);
    
public voidsetContentView(android.view.View view)
Set the screen content to an explicit view. This view is placed directly into the screen's view hierarchy. It can itself be a complex view hierarchy.

param
view The desired content to display.

        mWindow.setContentView(view);
    
public voidsetContentView(android.view.View view, android.view.ViewGroup.LayoutParams params)
Set the screen content to an explicit view. This view is placed directly into the screen's view hierarchy. It can itself be a complex view hierarhcy.

param
view The desired content to display.
param
params Layout parameters for the view.

        mWindow.setContentView(view, params);
    
public voidsetDismissMessage(android.os.Message msg)
Set a message to be sent when the dialog is dismissed.

param
msg The msg to send when the dialog is dismissed.

        mDismissMessage = msg;
    
public final voidsetFeatureDrawable(int featureId, android.graphics.drawable.Drawable drawable)
Convenience for calling {@link android.view.Window#setFeatureDrawable(int, Drawable)}.

        getWindow().setFeatureDrawable(featureId, drawable);
    
public final voidsetFeatureDrawableAlpha(int featureId, int alpha)
Convenience for calling {@link android.view.Window#setFeatureDrawableAlpha}.

        getWindow().setFeatureDrawableAlpha(featureId, alpha);
    
public final voidsetFeatureDrawableResource(int featureId, int resId)
Convenience for calling {@link android.view.Window#setFeatureDrawableResource}.

        getWindow().setFeatureDrawableResource(featureId, resId);
    
public final voidsetFeatureDrawableUri(int featureId, android.net.Uri uri)
Convenience for calling {@link android.view.Window#setFeatureDrawableUri}.

        getWindow().setFeatureDrawableUri(featureId, uri);
    
public voidsetOnCancelListener(OnCancelListener listener)
Set a listener to be invoked when the dialog is canceled.

This will only be invoked when the dialog is canceled. Cancel events alone will not capture all ways that the dialog might be dismissed. If the creator needs to know when a dialog is dismissed in general, use {@link #setOnDismissListener}.

param
listener The {@link DialogInterface.OnCancelListener} to use.

        if (mCancelAndDismissTaken != null) {
            throw new IllegalStateException(
                    "OnCancelListener is already taken by "
                    + mCancelAndDismissTaken + " and can not be replaced.");
        }
        if (listener != null) {
            mCancelMessage = mListenersHandler.obtainMessage(CANCEL, listener);
        } else {
            mCancelMessage = null;
        }
    
public voidsetOnDismissListener(OnDismissListener listener)
Set a listener to be invoked when the dialog is dismissed.

param
listener The {@link DialogInterface.OnDismissListener} to use.

        if (mCancelAndDismissTaken != null) {
            throw new IllegalStateException(
                    "OnDismissListener is already taken by "
                    + mCancelAndDismissTaken + " and can not be replaced.");
        }
        if (listener != null) {
            mDismissMessage = mListenersHandler.obtainMessage(DISMISS, listener);
        } else {
            mDismissMessage = null;
        }
    
public voidsetOnKeyListener(OnKeyListener onKeyListener)
Sets the callback that will be called if a key is dispatched to the dialog.

        mOnKeyListener = onKeyListener;
    
public voidsetOnShowListener(OnShowListener listener)
Sets a listener to be invoked when the dialog is shown.

param
listener The {@link DialogInterface.OnShowListener} to use.

        if (listener != null) {
            mShowMessage = mListenersHandler.obtainMessage(SHOW, listener);
        } else {
            mShowMessage = null;
        }
    
public final voidsetOwnerActivity(Activity activity)
Sets the Activity that owns this dialog. An example use: This Dialog will use the suggested volume control stream of the Activity.

param
activity The Activity that owns this dialog.

        mOwnerActivity = activity;
        
        getWindow().setVolumeControlStream(mOwnerActivity.getVolumeControlStream());
    
public voidsetTitle(java.lang.CharSequence title)
Set the title text for this dialog's window.

param
title The new text to display in the title.

        mWindow.setTitle(title);
        mWindow.getAttributes().setTitle(title);
    
public voidsetTitle(int titleId)
Set the title text for this dialog's window. The text is retrieved from the resources with the supplied identifier.

param
titleId the title's text resource identifier

        setTitle(mContext.getText(titleId));
    
public final voidsetVolumeControlStream(int streamType)
By default, this will use the owner Activity's suggested stream type.

see
Activity#setVolumeControlStream(int)
see
#setOwnerActivity(Activity)

        getWindow().setVolumeControlStream(streamType);
    
public voidshow()
Start the dialog and display it on screen. The window is placed in the application layer and opaque. Note that you should not override this method to do initialization when the dialog is shown, instead implement that in {@link #onStart}.

        if (mShowing) {
            if (mDecor != null) {
                if (mWindow.hasFeature(Window.FEATURE_ACTION_BAR)) {
                    mWindow.invalidatePanelMenu(Window.FEATURE_ACTION_BAR);
                }
                mDecor.setVisibility(View.VISIBLE);
            }
            return;
        }

        mCanceled = false;
        
        if (!mCreated) {
            dispatchOnCreate(null);
        }

        onStart();
        mDecor = mWindow.getDecorView();

        if (mActionBar == null && mWindow.hasFeature(Window.FEATURE_ACTION_BAR)) {
            final ApplicationInfo info = mContext.getApplicationInfo();
            mWindow.setDefaultIcon(info.icon);
            mWindow.setDefaultLogo(info.logo);
            mActionBar = new WindowDecorActionBar(this);
        }

        WindowManager.LayoutParams l = mWindow.getAttributes();
        if ((l.softInputMode
                & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) == 0) {
            WindowManager.LayoutParams nl = new WindowManager.LayoutParams();
            nl.copyFrom(l);
            nl.softInputMode |=
                    WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
            l = nl;
        }

        try {
            mWindowManager.addView(mDecor, l);
            mShowing = true;
    
            sendShowMessage();
        } finally {
        }
    
public booleantakeCancelAndDismissListeners(java.lang.String msg, OnCancelListener cancel, OnDismissListener dismiss)

hide

        if (mCancelAndDismissTaken != null) {
            mCancelAndDismissTaken = null;
        } else if (mCancelMessage != null || mDismissMessage != null) {
            return false;
        }
        
        setOnCancelListener(cancel);
        setOnDismissListener(dismiss);
        mCancelAndDismissTaken = msg;
        
        return true;
    
public voidtakeKeyEvents(boolean get)
Request that key events come to this dialog. Use this if your dialog has no views with focus, but the dialog still wants a chance to process key events.

param
get true if the dialog should receive key events, false otherwise
see
android.view.Window#takeKeyEvents

        mWindow.takeKeyEvents(get);
    
public voidunregisterForContextMenu(android.view.View view)

see
Activity#unregisterForContextMenu(View)

        view.setOnCreateContextMenuListener(null);