java.lang.Object | |
↳ | android.app.Dialog |
Known Direct Subclasses |
Known Indirect Subclasses |
Base class for Dialogs.
Note: Activities provide a facility to manage the creation, saving and
restoring of dialogs. See onCreateDialog(int)
,
onPrepareDialog(int, Dialog)
,
showDialog(int)
, and dismissDialog(int)
. If
these methods are used, 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 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);
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
android.content.DialogInterface
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a Dialog window that uses the default dialog frame style.
| |||||||||||
Create a Dialog window that uses a custom dialog style.
|
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Add an additional content view to the screen.
| |||||||||||
Cancel the dialog.
| |||||||||||
Dismiss this dialog, removing it from the screen.
| |||||||||||
Called to process key events.
| |||||||||||
Called to process population of
AccessibilityEvent s. | |||||||||||
Called to process touch screen events.
| |||||||||||
Called to process trackball events.
| |||||||||||
Finds a view that was identified by the id attribute from the XML that
was processed in
onStart() . | |||||||||||
Retrieve the Context this Dialog is running in.
| |||||||||||
Call
getCurrentFocus() on the
Window if this Activity to return the currently focused view. | |||||||||||
Returns the Activity that owns this Dialog.
| |||||||||||
Retrieve the current Window for the activity.
| |||||||||||
Hide the dialog, but do not dismiss it.
| |||||||||||
Called when the window has been attached to the window manager.
| |||||||||||
Called when the dialog has detected the user's press of the back
key.
| |||||||||||
This hook is called whenever the content view of the screen changes
(due to a call to
Window.setContentView or
Window.addContentView ). | |||||||||||
Called when the context menu for this view is being built.
| |||||||||||
It is usually safe to proxy this call to the owner activity's
onCreateOptionsMenu(Menu) if the client desires the same
menu for this Dialog. | |||||||||||
Initialize the contents of the menu for panel 'featureId'.
| |||||||||||
Instantiate the view to display in the panel for 'featureId'.
| |||||||||||
Called when the window has been attached to the window manager.
| |||||||||||
A key was pressed down.
| |||||||||||
Default implementation of
KeyEvent.Callback.onKeyLongPress() : always returns false (doesn't handle
the event). | |||||||||||
Default implementation of
KeyEvent.Callback.onKeyMultiple() : always returns false (doesn't handle
the event). | |||||||||||
A key was released.
| |||||||||||
Called when a panel's menu item has been selected by the user.
| |||||||||||
Called when a panel's menu is opened by the user.
| |||||||||||
Called when a panel is being closed.
| |||||||||||
It is usually safe to proxy this call to the owner activity's
onPrepareOptionsMenu(Menu) if the client desires the
same menu for this Dialog. | |||||||||||
Prepare a panel to be displayed.
| |||||||||||
Restore the state of the dialog from a previously saved bundle.
| |||||||||||
Saves the state of the dialog into a bundle.
| |||||||||||
This hook is called when the user signals the desire to start a search.
| |||||||||||
Called when a touch screen event was not handled by any of the views
under it.
| |||||||||||
Called when the trackball was moved and not handled by any of the
views inside of the activity.
| |||||||||||
This is called whenever the current window attributes change.
| |||||||||||
This hook is called whenever the window focus changes.
| |||||||||||
Enable extended window features.
| |||||||||||
Set a message to be sent when the dialog is canceled.
| |||||||||||
Sets whether this dialog is cancelable with the
BACK key. | |||||||||||
Sets whether this dialog is canceled when touched outside the window's
bounds.
| |||||||||||
Set the screen content to an explicit view.
| |||||||||||
Set the screen content to an explicit view.
| |||||||||||
Set the screen content from a layout resource.
| |||||||||||
Set a message to be sent when the dialog is dismissed.
| |||||||||||
Convenience for calling
setFeatureDrawable(int, Drawable) . | |||||||||||
Convenience for calling
setFeatureDrawableAlpha(int, int) . | |||||||||||
Convenience for calling
setFeatureDrawableResource(int, int) . | |||||||||||
Convenience for calling
setFeatureDrawableUri(int, Uri) . | |||||||||||
Set a listener to be invoked when the dialog is canceled.
| |||||||||||
Set a listener to be invoked when the dialog is dismissed.
| |||||||||||
Sets the callback that will be called if a key is dispatched to the dialog.
| |||||||||||
Sets the Activity that owns this dialog.
| |||||||||||
Set the title text for this dialog's window.
| |||||||||||
Set the title text for this dialog's window.
| |||||||||||
By default, this will use the owner Activity's suggested stream type.
| |||||||||||
Start the dialog and display it on screen.
| |||||||||||
Request that key events come to this dialog.
| |||||||||||
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Similar to
onCreate(Bundle) , you should initialized your dialog
in this method, including calling setContentView(View) . | |||||||||||
Called when the dialog is starting.
| |||||||||||
Called to tell you that you're stopping.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
| |||||||||||
From interface android.content.DialogInterface
| |||||||||||
From interface android.view.KeyEvent.Callback
| |||||||||||
From interface android.view.View.OnCreateContextMenuListener
| |||||||||||
From interface android.view.Window.Callback
|
Create a Dialog window that uses the default dialog frame style.
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. |
---|
Create a Dialog window that uses a custom dialog style.
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. |
---|---|
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. |
Add an additional content view to the screen. Added after any existing ones in the screen -- existing views are NOT removed.
view | The desired content to display. |
---|---|
params | Layout parameters for the view. |
Cancel the dialog. This is essentially the same as calling dismiss()
, but it will
also call your DialogInterface.OnCancelListener
(if registered).
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 onStop()
.
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.
event | The key event. |
---|
Called to process population of AccessibilityEvent
s.
event | The event. |
---|
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.
ev | The touch screen event. |
---|
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.
ev | The trackball event. |
---|
Finds a view that was identified by the id attribute from the XML that
was processed in onStart()
.
id | the identifier of the view to find |
---|
Retrieve the Context this Dialog is running in.
Call getCurrentFocus()
on the
Window if this Activity to return the currently focused view.
Returns the Activity that owns this Dialog. For example, if
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.
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.
Called when the window has been attached to the window manager.
See View.onAttachedToWindow()
for more information.
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.
This hook is called whenever the content view of the screen changes
(due to a call to
Window.setContentView
or
Window.addContentView
).
Called when the context menu for this view is being built. It is not safe to hold onto the menu after this method returns.
menu | The context menu that is being built |
---|---|
v | The view for which the context menu is being built |
menuInfo | Extra information about the item for which the context menu should be shown. This information will vary depending on the class of v. |
It is usually safe to proxy this call to the owner activity's
onCreateOptionsMenu(Menu)
if the client desires the same
menu for this Dialog.
Initialize the contents of the menu for panel 'featureId'. This is called if onCreatePanelView() returns null, giving you a standard menu in which you can place your items. It is only called once for the panel, the first time it is shown.
You can safely hold on to menu (and any items created from it), making modifications to it as desired, until the next time onCreatePanelMenu() is called for this feature.
featureId | The panel being created. |
---|---|
menu | The menu inside the panel. |
Instantiate the view to display in the panel for 'featureId'. You can return null, in which case the default content (typically a menu) will be created for you.
featureId | Which panel is being created. |
---|
Called when the window has been attached to the window manager.
See View.onDetachedFromWindow()
for more information.
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 onKeyUp(int, KeyEvent)
.
keyCode | The value in event.getKeyCode(). |
---|---|
event | Description of the key event. |
Default implementation of KeyEvent.Callback.onKeyLongPress()
: always returns false (doesn't handle
the event).
keyCode | The value in event.getKeyCode(). |
---|---|
event | Description of the key event. |
Default implementation of KeyEvent.Callback.onKeyMultiple()
: always returns false (doesn't handle
the event).
keyCode | The value in event.getKeyCode(). |
---|---|
repeatCount | Number of pairs as returned by event.getRepeatCount(). |
event | Description of the key event. |
A key was released.
The default implementation handles KEYCODE_BACK to close the dialog.
keyCode | The value in event.getKeyCode(). |
---|---|
event | Description of the key event. |
Called when a panel's menu item has been selected by the user.
featureId | The panel that the menu is in. |
---|---|
item | The menu item that was selected. |
Called when a panel's menu is opened by the user. This may also be called when the menu is changing from one type to another (for example, from the icon menu to the expanded menu).
featureId | The panel that the menu is in. |
---|---|
menu | The menu that is opened. |
Called when a panel is being closed. If another logical subsequent panel is being opened (and this panel is being closed to make room for the subsequent panel), this method will NOT be called.
featureId | The panel that is being displayed. |
---|---|
menu | If onCreatePanelView() returned null, this is the Menu being displayed in the panel. |
It is usually safe to proxy this call to the owner activity's
onPrepareOptionsMenu(Menu)
if the client desires the
same menu for this Dialog.
Prepare a panel to be displayed. This is called right before the panel window is shown, every time it is shown.
featureId | The panel that is being displayed. |
---|---|
view | The View that was returned by onCreatePanelView(). |
menu | If onCreatePanelView() returned null, this is the Menu being displayed in the panel. |
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 onSaveInstanceState()
,
so be sure to call through to super when overriding unless you want to
do all restoring of state yourself.
savedInstanceState | The state of the dialog previously saved by
onSaveInstanceState() .
|
---|
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.
This hook is called when the user signals the desire to start a search.
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.
event | The touch screen event being processed. |
---|
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.
event | The trackball event being processed. |
---|
This is called whenever the current window attributes change.
This hook is called whenever the window focus changes. See
View.onWindowFocusChanged(boolean)
for more information.
hasFocus | Whether the window now has focus. |
---|
Enable extended window features. This is a convenience for calling
getWindow().requestFeature()
.
featureId | The desired feature as defined in
Window . |
---|
Set a message to be sent when the dialog is canceled.
msg | The msg to send when the dialog is canceled. |
---|
Sets whether this dialog is cancelable with the
BACK
key.
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.
cancel | Whether the dialog should be canceled when touched outside the window. |
---|
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.
view | The desired content to display. |
---|---|
params | Layout parameters for the 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 hierarhcy.
view | The desired content to display. |
---|
Set the screen content from a layout resource. The resource will be inflated, adding all top-level views to the screen.
layoutResID | Resource ID to be inflated. |
---|
Set a message to be sent when the dialog is dismissed.
msg | The msg to send when the dialog is dismissed. |
---|
Convenience for calling
setFeatureDrawable(int, Drawable)
.
Convenience for calling
setFeatureDrawableAlpha(int, int)
.
Convenience for calling
setFeatureDrawableResource(int, int)
.
Convenience for calling
setFeatureDrawableUri(int, Uri)
.
Set a listener to be invoked when the dialog is canceled.
This will only be invoked when the dialog is canceled, if the creator
needs to know when it is dismissed in general, use
setOnDismissListener(DialogInterface.OnDismissListener)
.
listener | The DialogInterface.OnCancelListener to use.
|
---|
Set a listener to be invoked when the dialog is dismissed.
listener | The DialogInterface.OnDismissListener to use.
|
---|
Sets the callback that will be called if a key is dispatched to the dialog.
Sets the Activity that owns this dialog. An example use: This Dialog will use the suggested volume control stream of the Activity.
activity | The Activity that owns this dialog. |
---|
Set the title text for this dialog's window. The text is retrieved from the resources with the supplied identifier.
titleId | the title's text resource identifier |
---|
Set the title text for this dialog's window.
title | The new text to display in the title. |
---|
By default, this will use the owner Activity's suggested stream type.
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 onStart()
.
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.
get | true if the dialog should receive key events, false otherwise |
---|
Similar to onCreate(Bundle)
, you should initialized your dialog
in this method, including calling setContentView(View)
.
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 onSaveInstanceState() , or null if this
is the first time.
|
---|