Dialog
open class Dialog : DialogInterface, Window.Callback, KeyEvent.Callback, View.OnCreateContextMenuListener
kotlin.Any | |
↳ | android.app.Dialog |
Base class for Dialogs.
Note: Activities provide a facility to manage the creation, saving and restoring of dialogs. See Activity#onCreateDialog(int)
, Activity#onPrepareDialog(int, Dialog)
, Activity#showDialog(int)
, and Activity#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);
Summary
Inherited constants | |
---|---|
Public constructors | |
---|---|
Creates a dialog window that uses the default dialog theme. |
|
Creates a dialog window that uses a custom dialog style. |
Protected constructors | |
---|---|
Dialog(context: Context, cancelable: Boolean, cancelListener: DialogInterface.OnCancelListener?) |
Public methods | |
---|---|
open Unit |
addContentView(view: View, params: ViewGroup.LayoutParams?) Add an additional content view to the screen. |
open Unit |
cancel() Cancel the dialog. |
open Unit | |
open Unit |
create() Forces immediate creation of the dialog. |
open Unit |
dismiss() Dismiss this dialog, removing it from the screen. |
open Boolean |
Called to process generic motion events. |
open Boolean |
dispatchKeyEvent(event: KeyEvent) Called to process key events. |
open Boolean |
dispatchKeyShortcutEvent(event: KeyEvent) Called to process a key shortcut event. |
open Boolean |
Called to process population of |
open Boolean |
Called to process touch screen events. |
open Boolean |
Called to process trackball events. |
open T |
findViewById(id: Int) Finds the first descendant view with the given ID or |
open ActionBar? |
Retrieve the |
Context |
Retrieve the Context this Dialog is running in. |
open View? |
Call |
open LayoutInflater | |
open OnBackInvokedDispatcher |
Returns the |
Activity? |
Returns the Activity that owns this Dialog. |
SearchEvent? |
During the onSearchRequested() callbacks, this function will return the |
Int | |
open Window? |
Retrieve the current Window for the activity. |
open Unit |
hide() Hide the dialog, but do not dismiss it. |
open Unit | |
open Boolean | |
open Unit |
onActionModeFinished(mode: ActionMode!) Called when an action mode has been finished. |
open Unit |
onActionModeStarted(mode: ActionMode!) Called when an action mode has been started. |
open Unit | |
open Unit |
Called when the dialog has detected the user's press of the back key. |
open Unit | |
open Boolean |
onContextItemSelected(item: MenuItem) |
open Unit | |
open Unit |
onCreateContextMenu(: ContextMenu!, v: View!, : ContextMenu.ContextMenuInfo!) |
open Boolean |
It is usually safe to proxy this call to the owner activity's |
open Boolean |
onCreatePanelMenu(featureId: Int, : Menu) |
open View? |
onCreatePanelView(featureId: Int) |
open Unit | |
open Boolean |
onGenericMotionEvent(event: MotionEvent) Called when a generic motion event was not handled by any of the views inside of the dialog. |
open Boolean |
A key was pressed down. |
open Boolean |
onKeyLongPress(keyCode: Int, event: KeyEvent) Default implementation of |
open Boolean |
onKeyMultiple(keyCode: Int, repeatCount: Int, event: KeyEvent) Default implementation of |
open Boolean |
onKeyShortcut(keyCode: Int, event: KeyEvent) Called when a key shortcut event is not handled by any of the views in the Dialog. |
open Boolean |
A key was released. |
open Boolean |
onMenuItemSelected(featureId: Int, item: MenuItem) |
open Boolean |
onMenuOpened(featureId: Int, : Menu) |
open Boolean |
onOptionsItemSelected(item: MenuItem) |
open Unit | |
open Unit |
onPanelClosed(featureId: Int, : Menu) |
open Boolean |
It is usually safe to proxy this call to the owner activity's |
open Boolean |
onPreparePanel(featureId: Int, view: View?, : Menu) |
open Unit |
onRestoreInstanceState(savedInstanceState: Bundle) Restore the state of the dialog from a previously saved bundle. |
open Bundle |
Saves the state of the dialog into a bundle. |
open Boolean |
onSearchRequested(searchEvent: SearchEvent) This hook is called when the user signals the desire to start a search. |
open Boolean |
This hook is called when the user signals the desire to start a search. |
open Boolean |
onTouchEvent(event: MotionEvent) Called when a touch screen event was not handled by any of the views under it. |
open Boolean |
onTrackballEvent(event: MotionEvent) Called when the trackball was moved and not handled by any of the views inside of the activity. |
open Unit | |
open Unit |
onWindowFocusChanged(hasFocus: Boolean) |
open ActionMode? |
onWindowStartingActionMode(callback: ActionMode.Callback!) |
open ActionMode? |
onWindowStartingActionMode(callback: ActionMode.Callback!, type: Int) |
open Unit |
openContextMenu(view: View) |
open Unit | |
open Unit |
registerForContextMenu(view: View) |
Boolean |
requestWindowFeature(featureId: Int) Enable extended window features. |
T |
requireViewById(id: Int) Finds the first descendant view with the given ID or throws an IllegalArgumentException if the ID is invalid (< 0), there is no matching view in the hierarchy, or the dialog has not yet been fully created (for example, via |
open Unit |
setCancelMessage(msg: Message?) Set a message to be sent when the dialog is canceled. |
open Unit |
setCancelable(flag: Boolean) Sets whether this dialog is cancelable with the |
open Unit |
setCanceledOnTouchOutside(cancel: Boolean) Sets whether this dialog is canceled when touched outside the window's bounds. |
open Unit |
setContentView(layoutResID: Int) Set the screen content from a layout resource. |
open Unit |
setContentView(view: View) Set the screen content to an explicit view. |
open Unit |
setContentView(view: View, params: ViewGroup.LayoutParams?) Set the screen content to an explicit view. |
open Unit |
setDismissMessage(msg: Message?) Set a message to be sent when the dialog is dismissed. |
Unit |
setFeatureDrawable(featureId: Int, drawable: Drawable?) Convenience for calling |
Unit |
setFeatureDrawableAlpha(featureId: Int, alpha: Int) Convenience for calling |
Unit |
setFeatureDrawableResource(featureId: Int, resId: Int) Convenience for calling |
Unit |
setFeatureDrawableUri(featureId: Int, uri: Uri?) Convenience for calling |
open Unit |
setOnCancelListener(listener: DialogInterface.OnCancelListener?) Set a listener to be invoked when the dialog is canceled. |
open Unit |
Set a listener to be invoked when the dialog is dismissed. |
open Unit |
setOnKeyListener(onKeyListener: DialogInterface.OnKeyListener?) Sets the callback that will be called if a key is dispatched to the dialog. |
open Unit |
setOnShowListener(listener: DialogInterface.OnShowListener?) Sets a listener to be invoked when the dialog is shown. |
Unit |
setOwnerActivity(activity: Activity) Sets the Activity that owns this dialog. |
open Unit |
setTitle(title: CharSequence?) Set the title text for this dialog's window. |
open Unit |
Set the title text for this dialog's window. |
Unit |
setVolumeControlStream(streamType: Int) By default, this will use the owner Activity's suggested stream type. |
open Unit |
show() Start the dialog and display it on screen. |
open Unit |
takeKeyEvents(get: Boolean) Request that key events come to this dialog. |
open Unit |
unregisterForContextMenu(view: View) |
Protected methods | |
---|---|
open Unit |
Similar to android. |
open Unit |
onStart() Called when the dialog is starting. |
open Unit |
onStop() Called to tell you that you're stopping. |
Inherited functions | |
---|---|
Public constructors
Dialog
Dialog(context: Context)
Creates a dialog window that uses the default dialog theme.
The supplied context
is used to obtain the window manager and base theme used to present the dialog.
Parameters | |
---|---|
context |
Context: the context in which the dialog should run This value cannot be null . |
Dialog
Dialog(
context: Context,
themeResId: Int)
Creates a dialog window that uses a custom dialog style.
The supplied context
is used to obtain the window manager and base theme used to present the dialog.
The supplied theme
is applied on top of the context's theme. See Style and Theme Resources for more information about defining and using styles.
Parameters | |
---|---|
context |
Context: the context in which the dialog should run This value cannot be null . |
themeResId |
Int: a style resource describing the theme to use for the window, or 0 to use the default dialog theme |
Protected constructors
Dialog
protected Dialog(
context: Context,
cancelable: Boolean,
cancelListener: DialogInterface.OnCancelListener?)
Parameters | |
---|---|
context |
Context: This value cannot be null . |
cancelListener |
DialogInterface.OnCancelListener?: This value may be null . |
Public methods
addContentView
open fun addContentView(
view: View,
params: ViewGroup.LayoutParams?
): Unit
Add an additional content view to the screen. Added after any existing ones in the screen -- existing views are NOT removed.
Parameters | |
---|---|
view |
View: The desired content to display. This value cannot be null . |
params |
ViewGroup.LayoutParams?: Layout parameters for the view. This value may be null . |
cancel
open fun cancel(): Unit
Cancel the dialog. This is essentially the same as calling dismiss()
, but it will also call your DialogInterface.OnCancelListener
(if registered).
create
open fun create(): Unit
Forces immediate creation of the dialog.
Note that you should not override this method to perform dialog creation. Rather, override onCreate(android.os.Bundle)
.
dismiss
open fun dismiss(): Unit
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
.
dispatchGenericMotionEvent
open fun dispatchGenericMotionEvent(ev: MotionEvent): Boolean
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.
Parameters | |
---|---|
event |
The generic motion event. |
ev |
MotionEvent: The generic motion event. This value cannot be null . |
Return | |
---|---|
Boolean |
boolean Return true if this event was consumed. |
dispatchKeyEvent
open fun dispatchKeyEvent(event: KeyEvent): Boolean
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.
Parameters | |
---|---|
event |
KeyEvent: The key event. This value cannot be null . |
Return | |
---|---|
Boolean |
boolean Return true if this event was consumed. |
dispatchKeyShortcutEvent
open fun dispatchKeyShortcutEvent(event: KeyEvent): Boolean
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.
Parameters | |
---|---|
event |
KeyEvent: The key shortcut event. This value cannot be null . |
Return | |
---|---|
Boolean |
True if this event was consumed. |
dispatchPopulateAccessibilityEvent
open fun dispatchPopulateAccessibilityEvent(event: AccessibilityEvent): Boolean
Called to process population of AccessibilityEvent
s.
Parameters | |
---|---|
event |
AccessibilityEvent: This value cannot be null . |
Return | |
---|---|
Boolean |
boolean Return true if event population was completed. |
dispatchTouchEvent
open fun dispatchTouchEvent(ev: MotionEvent): Boolean
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.
Parameters | |
---|---|
event |
The touch screen event. |
ev |
MotionEvent: The touch screen event. This value cannot be null . |
Return | |
---|---|
Boolean |
boolean Return true if this event was consumed. |
dispatchTrackballEvent
open fun dispatchTrackballEvent(ev: MotionEvent): Boolean
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.
Parameters | |
---|---|
event |
The trackball event. |
ev |
MotionEvent: The trackball event. This value cannot be null . |
Return | |
---|---|
Boolean |
boolean Return true if this event was consumed. |
findViewById
open fun <T : View!> findViewById(id: Int): T
Finds the first descendant view with the given ID or null
if the ID is invalid (< 0), there is no matching view in the hierarchy, or the dialog has not yet been fully created (for example, via show()
or create()
).
Note: In most cases -- depending on compiler support -- the resulting view is automatically cast to the target class type. If the target class type is unconstrained, an explicit cast may be necessary.
Parameters | |
---|---|
id |
Int: the ID to search for |
Return | |
---|---|
T |
a view with given ID if found, or null otherwise |
getActionBar
open fun getActionBar(): ActionBar?
Retrieve the ActionBar
attached to this dialog, if present.
Return | |
---|---|
ActionBar? |
The ActionBar attached to the dialog or null if no ActionBar is present. |
getContext
fun getContext(): Context
Retrieve the Context this Dialog is running in.
Return | |
---|---|
Context |
Context The Context used by the Dialog. This value cannot be null . |
getCurrentFocus
open fun getCurrentFocus(): View?
Call android.view.Window#getCurrentFocus
on the Window if this Activity to return the currently focused view.
Return | |
---|---|
View? |
View The current View with focus or null. |
getLayoutInflater
open fun getLayoutInflater(): LayoutInflater
Return | |
---|---|
LayoutInflater |
This value cannot be null . |
getOnBackInvokedDispatcher
open fun getOnBackInvokedDispatcher(): OnBackInvokedDispatcher
Returns the OnBackInvokedDispatcher
instance associated with the window that this dialog is attached to.
Return | |
---|---|
OnBackInvokedDispatcher |
This value cannot be null . |
getOwnerActivity
fun getOwnerActivity(): Activity?
Returns the Activity that owns this Dialog. For example, if 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 | |
---|---|
Activity? |
The Activity that owns this Dialog. |
getSearchEvent
fun getSearchEvent(): SearchEvent?
During the onSearchRequested() callbacks, this function will return the SearchEvent
that triggered the callback, if it exists.
Return | |
---|---|
SearchEvent? |
SearchEvent The SearchEvent that triggered the #onSearchRequested callback. This value may be null . |
getWindow
open fun getWindow(): Window?
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? |
Window The current window, or null if the activity is not visual. |
isShowing
open fun isShowing(): Boolean
Return | |
---|---|
Boolean |
Whether the dialog is currently showing. |
onActionModeFinished
open fun onActionModeFinished(mode: ActionMode!): Unit
Called when an action mode has been finished. The appropriate mode callback method will have already been invoked. Note that if you override this method you should always call through to the superclass implementation by calling super.onActionModeFinished(mode).
If you override this method you must call through to the superclass implementation.
Parameters | |
---|---|
mode |
ActionMode!: The mode that was just finished. |
onActionModeStarted
open fun onActionModeStarted(mode: ActionMode!): Unit
Called when an action mode has been started. The appropriate mode callback method will have already been invoked. Note that if you override this method you should always call through to the superclass implementation by calling super.onActionModeStarted(mode).
If you override this method you must call through to the superclass implementation.
Parameters | |
---|---|
mode |
ActionMode!: The new mode that has just been started. |
onBackPressed
open funonBackPressed(): Unit
Deprecated: Use Starting from Android 13 (API level 33), back event handling is moving to an ahead-of-time model and OnBackInvokedCallback
or androidx.activity.OnBackPressedCallback
to handle back navigation instead.
onBackPressed()
and KeyEvent#KEYCODE_BACK
should not be used to handle back events (back gesture or back button click). Instead, an OnBackInvokedCallback
should be registered using Dialog#getOnBackInvokedDispatcher()
.registerOnBackInvokedCallback(priority, callback)
.
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 you target version android.os.Build.VERSION_CODES#TIRAMISU
or later, you should not use this method but register an OnBackInvokedCallback
on an OnBackInvokedDispatcher
that you can retrieve using getOnBackInvokedDispatcher()
. You should also set android:enableOnBackInvokedCallback="true"
in the application manifest.
Alternatively, you can use androidx.activity.ComponentDialog#getOnBackPressedDispatcher()
for backward compatibility.
onContextItemSelected
open fun onContextItemSelected(item: MenuItem): Boolean
Parameters | |
---|---|
item |
MenuItem: This value cannot be null . |
onContextMenuClosed
open fun onContextMenuClosed(: Menu): Unit
Parameters | |
---|---|
menu |
Menu: This value cannot be null . |
onCreateContextMenu
open fun onCreateContextMenu(
: ContextMenu!,
v: View!,
: ContextMenu.ContextMenuInfo!
): Unit
Parameters | |
---|---|
menu |
ContextMenu!: The context menu that is being built |
v |
View!: The view for which the context menu is being built |
menuInfo |
ContextMenu.ContextMenuInfo!: Extra information about the item for which the context menu should be shown. This information will vary depending on the class of v. |
onCreateOptionsMenu
open fun onCreateOptionsMenu(: Menu): Boolean
It is usually safe to proxy this call to the owner activity's Activity#onCreateOptionsMenu(Menu)
if the client desires the same menu for this Dialog.
Parameters | |
---|---|
menu |
Menu: This value cannot be null . |
onCreatePanelMenu
open fun onCreatePanelMenu(
featureId: Int,
: Menu
): Boolean
Parameters | |
---|---|
featureId |
Int: The panel being created. |
menu |
Menu: This value cannot be null . |
Return | |
---|---|
Boolean |
boolean You must return true for the panel to be displayed; if you return false it will not be shown. |
onCreatePanelView
open fun onCreatePanelView(featureId: Int): View?
Parameters | |
---|---|
featureId |
Int: Which panel is being created. |
Return | |
---|---|
View? |
view The top-level view to place in the panel. |
onGenericMotionEvent
open fun onGenericMotionEvent(event: MotionEvent): Boolean
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 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 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 View#onGenericMotionEvent(MotionEvent)
for an example of how to handle this event.
Parameters | |
---|---|
event |
MotionEvent: The generic motion event being processed. This value cannot be null . |
Return | |
---|---|
Boolean |
Return true if you have consumed the event, false if you haven't. The default implementation always returns false. |
onKeyDown
open fun onKeyDown(
keyCode: Int,
event: KeyEvent
): Boolean
A key was pressed down.
If the focused view didn't want this event, this method is called.
Default implementation consumes KEYCODE_BACK
and, as of P
, KEYCODE_ESCAPE
to later handle them in onKeyUp
.
Parameters | |
---|---|
keyCode |
Int: The value in event.getKeyCode(). |
event |
KeyEvent: This value cannot be null . |
Return | |
---|---|
Boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
See Also
onKeyLongPress
open fun onKeyLongPress(
keyCode: Int,
event: KeyEvent
): Boolean
Default implementation of KeyEvent.Callback.onKeyLongPress()
: always returns false (doesn't handle the event).
Parameters | |
---|---|
keyCode |
Int: The value in event.getKeyCode(). |
event |
KeyEvent: This value cannot be null . |
Return | |
---|---|
Boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
onKeyMultiple
open fun onKeyMultiple(
keyCode: Int,
repeatCount: Int,
event: KeyEvent
): Boolean
Default implementation of KeyEvent.Callback.onKeyMultiple()
: always returns false (doesn't handle the event).
Parameters | |
---|---|
keyCode |
Int: The value in event.getKeyCode(). |
count |
Number of pairs as returned by event.getRepeatCount(). |
event |
KeyEvent: This value cannot be null . |
Return | |
---|---|
Boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
onKeyShortcut
open fun onKeyShortcut(
keyCode: Int,
event: KeyEvent
): Boolean
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 shortcut
property of menu items.
Parameters | |
---|---|
keyCode |
Int: The value in event.getKeyCode(). |
event |
KeyEvent: Description of the key event. This value cannot be null . |
Return | |
---|---|
Boolean |
True if the key shortcut was handled. |
onKeyUp
open fun onKeyUp(
keyCode: Int,
event: KeyEvent
): Boolean
A key was released.
Default implementation consumes KEYCODE_BACK
and, as of P
, KEYCODE_ESCAPE
to close the dialog.
Parameters | |
---|---|
keyCode |
Int: The value in event.getKeyCode(). |
event |
KeyEvent: This value cannot be null . |
Return | |
---|---|
Boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
See Also
onMenuItemSelected
open fun onMenuItemSelected(
featureId: Int,
item: MenuItem
): Boolean
Parameters | |
---|---|
featureId |
Int: The panel that the menu is in. |
item |
MenuItem: This value cannot be null . |
Return | |
---|---|
Boolean |
boolean Return true to finish processing of selection, or false to perform the normal menu handling (calling its Runnable or sending a Message to its target Handler). |
onMenuOpened
open fun onMenuOpened(
featureId: Int,
: Menu
): Boolean
Parameters | |
---|---|
featureId |
Int: The panel that the menu is in. |
menu |
Menu: This value cannot be null . |
Return | |
---|---|
Boolean |
Return true to allow the menu to open, or false to prevent the menu from opening. |
onOptionsItemSelected
open fun onOptionsItemSelected(item: MenuItem): Boolean
Parameters | |
---|---|
item |
MenuItem: This value cannot be null . |
onOptionsMenuClosed
open fun onOptionsMenuClosed(: Menu): Unit
Parameters | |
---|---|
menu |
Menu: This value cannot be null . |
onPanelClosed
open fun onPanelClosed(
featureId: Int,
: Menu
): Unit
Parameters | |
---|---|
featureId |
Int: The panel that is being displayed. |
menu |
Menu: This value cannot be null . |
onPrepareOptionsMenu
open fun onPrepareOptionsMenu(: Menu): Boolean
It is usually safe to proxy this call to the owner activity's Activity#onPrepareOptionsMenu(Menu)
if the client desires the same menu for this Dialog.
Parameters | |
---|---|
menu |
Menu: This value cannot be null . |
onPreparePanel
open fun onPreparePanel(
featureId: Int,
view: View?,
: Menu
): Boolean
Parameters | |
---|---|
featureId |
Int: The panel that is being displayed. |
view |
View?: This value may be null . |
menu |
Menu: This value cannot be null . |
Return | |
---|---|
Boolean |
boolean You must return true for the panel to be displayed; if you return false it will not be shown. |
onRestoreInstanceState
open fun onRestoreInstanceState(savedInstanceState: Bundle): Unit
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.
Parameters | |
---|---|
savedInstanceState |
Bundle: The state of the dialog previously saved by onSaveInstanceState() . This value cannot be null . |
onSaveInstanceState
open fun onSaveInstanceState(): Bundle
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 | |
---|---|
Bundle |
A bundle with the state of the dialog. This value cannot be null . |
onSearchRequested
open fun onSearchRequested(searchEvent: SearchEvent): Boolean
This hook is called when the user signals the desire to start a search.
Parameters | |
---|---|
searchEvent |
SearchEvent: This value cannot be null . |
Return | |
---|---|
Boolean |
true if search launched, false if activity refuses (blocks) |
onSearchRequested
open fun onSearchRequested(): Boolean
This hook is called when the user signals the desire to start a search.
Return | |
---|---|
Boolean |
true if search launched, false if activity refuses (blocks) |
onTouchEvent
open fun onTouchEvent(event: MotionEvent): Boolean
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.
Parameters | |
---|---|
event |
MotionEvent: The touch screen event being processed. This value cannot be null . |
Return | |
---|---|
Boolean |
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. |
onTrackballEvent
open fun onTrackballEvent(event: MotionEvent): Boolean
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.
Parameters | |
---|---|
event |
MotionEvent: The trackball event being processed. This value cannot be null . |
Return | |
---|---|
Boolean |
Return true if you have consumed the event, false if you haven't. The default implementation always returns false. |
onWindowAttributesChanged
open fun onWindowAttributesChanged(params: WindowManager.LayoutParams!): Unit
onWindowFocusChanged
open fun onWindowFocusChanged(hasFocus: Boolean): Unit
Parameters | |
---|---|
hasFocus |
Boolean: Whether the window now has focus. |
onWindowStartingActionMode
open fun onWindowStartingActionMode(callback: ActionMode.Callback!): ActionMode?
Parameters | |
---|---|
callback |
ActionMode.Callback!: Callback to control the lifecycle of this action mode |
Return | |
---|---|
ActionMode? |
The ActionMode that was started, or null if the system should present it |
onWindowStartingActionMode
open fun onWindowStartingActionMode(
callback: ActionMode.Callback!,
type: Int
): ActionMode?
Parameters | |
---|---|
callback |
ActionMode.Callback!: Callback to control the lifecycle of this action mode |
type |
Int: One of ActionMode#TYPE_PRIMARY or ActionMode#TYPE_FLOATING . |
Return | |
---|---|
ActionMode? |
The ActionMode that was started, or null if the system should present it |
openContextMenu
open fun openContextMenu(view: View): Unit
Parameters | |
---|---|
view |
View: This value cannot be null . |
registerForContextMenu
open fun registerForContextMenu(view: View): Unit
Parameters | |
---|---|
view |
View: This value cannot be null . |
requestWindowFeature
fun requestWindowFeature(featureId: Int): Boolean
Enable extended window features. This is a convenience for calling getWindow().requestFeature()
.
Parameters | |
---|---|
featureId |
Int: The desired feature as defined in android.view.Window . |
Return | |
---|---|
Boolean |
Returns true if the requested feature is supported and now enabled. |
See Also
requireViewById
fun <T : View!> requireViewById(id: Int): T
Finds the first descendant view with the given ID or throws an IllegalArgumentException if the ID is invalid (< 0), there is no matching view in the hierarchy, or the dialog has not yet been fully created (for example, via show()
or create()
).
Note: In most cases -- depending on compiler support -- the resulting view is automatically cast to the target class type. If the target class type is unconstrained, an explicit cast may be necessary.
Parameters | |
---|---|
id |
Int: the ID to search for |
Return | |
---|---|
T |
a view with given ID This value cannot be null . |
setCancelMessage
open fun setCancelMessage(msg: Message?): Unit
Set a message to be sent when the dialog is canceled.
Parameters | |
---|---|
msg |
Message?: The msg to send when the dialog is canceled. This value may be null . |
setCancelable
open fun setCancelable(flag: Boolean): Unit
Sets whether this dialog is cancelable with the BACK
key.
setCanceledOnTouchOutside
open fun setCanceledOnTouchOutside(cancel: Boolean): Unit
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.
Parameters | |
---|---|
cancel |
Boolean: Whether the dialog should be canceled when touched outside the window. |
setContentView
open fun setContentView(layoutResID: Int): Unit
Set the screen content from a layout resource. The resource will be inflated, adding all top-level views to the screen.
Parameters | |
---|---|
layoutResID |
Int: Resource ID to be inflated. |
setContentView
open fun setContentView(view: View): Unit
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.
Parameters | |
---|---|
view |
View: The desired content to display. This value cannot be null . |
setContentView
open fun setContentView(
view: View,
params: ViewGroup.LayoutParams?
): Unit
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.
Parameters | |
---|---|
view |
View: The desired content to display. This value cannot be null . |
params |
ViewGroup.LayoutParams?: Layout parameters for the view. This value may be null . |
setDismissMessage
open fun setDismissMessage(msg: Message?): Unit
Set a message to be sent when the dialog is dismissed.
Parameters | |
---|---|
msg |
Message?: The msg to send when the dialog is dismissed. This value may be null . |
setFeatureDrawable
fun setFeatureDrawable(
featureId: Int,
drawable: Drawable?
): Unit
Convenience for calling android.view.Window#setFeatureDrawable(int, Drawable)
.
Parameters | |
---|---|
drawable |
Drawable?: This value may be null . |
setFeatureDrawableAlpha
fun setFeatureDrawableAlpha(
featureId: Int,
alpha: Int
): Unit
Convenience for calling android.view.Window#setFeatureDrawableAlpha
.
setFeatureDrawableResource
fun setFeatureDrawableResource(
featureId: Int,
resId: Int
): Unit
Convenience for calling android.view.Window#setFeatureDrawableResource
.
setFeatureDrawableUri
fun setFeatureDrawableUri(
featureId: Int,
uri: Uri?
): Unit
Convenience for calling android.view.Window#setFeatureDrawableUri
.
Parameters | |
---|---|
uri |
Uri?: This value may be null . |
setOnCancelListener
open fun setOnCancelListener(listener: DialogInterface.OnCancelListener?): Unit
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 setOnDismissListener
.
Parameters | |
---|---|
listener |
DialogInterface.OnCancelListener?: The DialogInterface.OnCancelListener to use. This value may be null . |
setOnDismissListener
open fun setOnDismissListener(listener: DialogInterface.OnDismissListener?): Unit
Set a listener to be invoked when the dialog is dismissed.
Parameters | |
---|---|
listener |
DialogInterface.OnDismissListener?: The DialogInterface.OnDismissListener to use. This value may be null . |
setOnKeyListener
open fun setOnKeyListener(onKeyListener: DialogInterface.OnKeyListener?): Unit
Sets the callback that will be called if a key is dispatched to the dialog.
Parameters | |
---|---|
onKeyListener |
DialogInterface.OnKeyListener?: This value may be null . |
setOnShowListener
open fun setOnShowListener(listener: DialogInterface.OnShowListener?): Unit
Sets a listener to be invoked when the dialog is shown.
Parameters | |
---|---|
listener |
DialogInterface.OnShowListener?: The DialogInterface.OnShowListener to use. This value may be null . |
setOwnerActivity
fun setOwnerActivity(activity: Activity): Unit
Sets the Activity that owns this dialog. An example use: This Dialog will use the suggested volume control stream of the Activity.
Parameters | |
---|---|
activity |
Activity: The Activity that owns this dialog. This value cannot be null . |
setTitle
open fun setTitle(title: CharSequence?): Unit
Set the title text for this dialog's window.
Parameters | |
---|---|
title |
CharSequence?: The new text to display in the title. This value may be null . |
setTitle
open fun setTitle(titleId: Int): Unit
Set the title text for this dialog's window. The text is retrieved from the resources with the supplied identifier.
Parameters | |
---|---|
titleId |
Int: the title's text resource identifier |
setVolumeControlStream
fun setVolumeControlStream(streamType: Int): Unit
By default, this will use the owner Activity's suggested stream type.
show
open fun show(): Unit
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
.
takeKeyEvents
open fun takeKeyEvents(get: Boolean): Unit
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.
Parameters | |
---|---|
get |
Boolean: true if the dialog should receive key events, false otherwise |
See Also
unregisterForContextMenu
open fun unregisterForContextMenu(view: View): Unit
Parameters | |
---|---|
view |
View: This value cannot be null . |
Protected methods
onCreate
protected open fun onCreate(savedInstanceState: Bundle!): Unit
Similar to android.app.Activity#onCreate, you should initialize your dialog in this method, including calling #setContentView.
Parameters | |
---|---|
savedInstanceState |
Bundle!: If this dialog is being reinitialized 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. |
onStop
protected open fun onStop(): Unit
Called to tell you that you're stopping.