Added in API level 1

Callback

interface Callback
android.view.Window.Callback

API from a Window back to its caller. This allows the client to intercept key dispatching, panels and menus, etc.

Summary

Public methods
abstract Boolean

Called to process generic motion events.

abstract Boolean

Called to process key events.

abstract Boolean

Called to process a key shortcut event.

abstract Boolean

Called to process population of AccessibilityEvents.

abstract Boolean

Called to process touch screen events.

abstract Boolean

Called to process trackball events.

abstract Unit

Called when an action mode has been finished.

abstract Unit

Called when an action mode has been started.

abstract Unit

Called when the window has been attached to the window manager.

abstract Unit

This hook is called whenever the content view of the screen changes (due to a call to Window.setContentView or Window.addContentView).

abstract Boolean
onCreatePanelMenu(featureId: Int, menu: Menu)

Initialize the contents of the menu for panel 'featureId'.

abstract View?
onCreatePanelView(featureId: Int)

Instantiate the view to display in the panel for 'featureId'.

abstract Unit

Called when the window has been detached from the window manager.

abstract Boolean
onMenuItemSelected(featureId: Int, item: MenuItem)

Called when a panel's menu item has been selected by the user.

abstract Boolean
onMenuOpened(featureId: Int, menu: Menu)

Called when a panel's menu is opened by the user.

abstract Unit
onPanelClosed(featureId: Int, menu: Menu)

Called when a panel is being closed.

open Unit

Called when pointer capture is enabled or disabled for the current window.

abstract Boolean
onPreparePanel(featureId: Int, view: View?, menu: Menu)

Prepare a panel to be displayed.

open Unit

Called when Keyboard Shortcuts are requested for the current window.

abstract Boolean

Called when the user signals the desire to start a search.

abstract Boolean

Called when the user signals the desire to start a search.

abstract Unit

This is called whenever the current window attributes change.

abstract Unit

This hook is called whenever the window focus changes.

abstract ActionMode?

Called when an action mode is being started for this window.

abstract ActionMode?

Called when an action mode is being started for this window.

Public methods

dispatchGenericMotionEvent

Added in API level 12
abstract fun dispatchGenericMotionEvent(event: MotionEvent!): Boolean

Called to process generic motion events. At the very least your implementation must call android.view.Window#superDispatchGenericMotionEvent to do the standard processing.

Parameters
event MotionEvent!: The generic motion event.
Return
Boolean boolean Return true if this event was consumed.

dispatchKeyEvent

Added in API level 1
abstract fun dispatchKeyEvent(event: KeyEvent!): Boolean

Called to process key events. At the very least your implementation must call android.view.Window#superDispatchKeyEvent to do the standard key processing.

Parameters
event KeyEvent!: The key event.
Return
Boolean boolean Return true if this event was consumed.

dispatchKeyShortcutEvent

Added in API level 11
abstract fun dispatchKeyShortcutEvent(event: KeyEvent!): Boolean

Called to process a key shortcut event. At the very least your implementation must call android.view.Window#superDispatchKeyShortcutEvent to do the standard key shortcut processing.

Parameters
event KeyEvent!: The key shortcut event.
Return
Boolean True if this event was consumed.

dispatchPopulateAccessibilityEvent

Added in API level 4
abstract fun dispatchPopulateAccessibilityEvent(event: AccessibilityEvent!): Boolean

Called to process population of AccessibilityEvents.

Parameters
event AccessibilityEvent!: The event.
Return
Boolean boolean Return true if event population was completed.

dispatchTouchEvent

Added in API level 1
abstract fun dispatchTouchEvent(event: MotionEvent!): Boolean

Called to process touch screen events. At the very least your implementation must call android.view.Window#superDispatchTouchEvent to do the standard touch screen processing.

Parameters
event MotionEvent!: The touch screen event.
Return
Boolean boolean Return true if this event was consumed.

dispatchTrackballEvent

Added in API level 1
abstract fun dispatchTrackballEvent(event: MotionEvent!): Boolean

Called to process trackball events. At the very least your implementation must call android.view.Window#superDispatchTrackballEvent to do the standard trackball processing.

Parameters
event MotionEvent!: The trackball event.
Return
Boolean boolean Return true if this event was consumed.

onActionModeFinished

Added in API level 11
abstract fun onActionModeFinished(mode: ActionMode!): Unit

Called when an action mode has been finished. The appropriate mode callback method will have already been invoked.

Parameters
mode ActionMode!: The mode that was just finished.

onActionModeStarted

Added in API level 11
abstract fun onActionModeStarted(mode: ActionMode!): Unit

Called when an action mode has been started. The appropriate mode callback method will have already been invoked.

Parameters
mode ActionMode!: The new mode that has just been started.

onAttachedToWindow

Added in API level 5
abstract fun onAttachedToWindow(): Unit

Called when the window has been attached to the window manager. See View.onAttachedToWindow() for more information.

onContentChanged

Added in API level 1
abstract fun onContentChanged(): Unit

This hook is called whenever the content view of the screen changes (due to a call to Window.setContentView or Window.addContentView).

onCreatePanelMenu

Added in API level 1
abstract fun onCreatePanelMenu(
    featureId: Int,
    menu: Menu
): Boolean

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.

Parameters
featureId Int: The panel being created.
menu Menu: The menu inside the panel. 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

Added in API level 1
abstract fun onCreatePanelView(featureId: Int): View?

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.

Parameters
featureId Int: Which panel is being created.
Return
View? view The top-level view to place in the panel.

See Also

onDetachedFromWindow

Added in API level 5
abstract fun onDetachedFromWindow(): Unit

Called when the window has been detached from the window manager. See View.onDetachedFromWindow() for more information.

onMenuItemSelected

Added in API level 1
abstract fun onMenuItemSelected(
    featureId: Int,
    item: MenuItem
): Boolean

Called when a panel's menu item has been selected by the user.

Parameters
featureId Int: The panel that the menu is in.
item MenuItem: The menu item that was selected. 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

Added in API level 1
abstract fun onMenuOpened(
    featureId: Int,
    menu: Menu
): Boolean

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

Parameters
featureId Int: The panel that the menu is in.
menu Menu: The menu that is opened. This value cannot be null.
Return
Boolean Return true to allow the menu to open, or false to prevent the menu from opening.

onPanelClosed

Added in API level 1
abstract fun onPanelClosed(
    featureId: Int,
    menu: Menu
): Unit

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.

Parameters
featureId Int: The panel that is being displayed.
menu Menu: If onCreatePanelView() returned null, this is the Menu being displayed in the panel.

onPointerCaptureChanged

Added in API level 26
open fun onPointerCaptureChanged(hasCapture: Boolean): Unit

Called when pointer capture is enabled or disabled for the current window.

Parameters
hasCapture Boolean: True if the window has pointer capture.

onPreparePanel

Added in API level 1
abstract fun onPreparePanel(
    featureId: Int,
    view: View?,
    menu: Menu
): Boolean

Prepare a panel to be displayed. This is called right before the panel window is shown, every time it is shown.

Parameters
featureId Int: The panel that is being displayed.
view View?: The View that was returned by onCreatePanelView(). This value may be null.
menu Menu: If onCreatePanelView() returned null, this is the Menu being displayed in the panel.
Return
Boolean boolean You must return true for the panel to be displayed; if you return false it will not be shown.

onProvideKeyboardShortcuts

Added in API level 24
open fun onProvideKeyboardShortcuts(
    data: MutableList<KeyboardShortcutGroup!>!,
    menu: Menu?,
    deviceId: Int
): Unit

Called when Keyboard Shortcuts are requested for the current window.

Parameters
data MutableList<KeyboardShortcutGroup!>!: The data list to populate with shortcuts.
menu Menu?: The current menu, which may be null.
deviceId Int: The id for the connected device the shortcuts should be provided for.

onSearchRequested

Added in API level 1
abstract fun onSearchRequested(): Boolean

Called when the user signals the desire to start a search.

Return
Boolean true if search launched, false if activity refuses (blocks)

onSearchRequested

Added in API level 23
abstract fun onSearchRequested(searchEvent: SearchEvent!): Boolean

Called when the user signals the desire to start a search.

Parameters
searchEvent SearchEvent!: A SearchEvent describing the signal to start a search.
Return
Boolean true if search launched, false if activity refuses (blocks)

onWindowAttributesChanged

Added in API level 1
abstract fun onWindowAttributesChanged(attrs: WindowManager.LayoutParams!): Unit

This is called whenever the current window attributes change.

onWindowFocusChanged

Added in API level 1
abstract fun onWindowFocusChanged(hasFocus: Boolean): Unit

This hook is called whenever the window focus changes. See View.onWindowFocusChangedNotLocked(boolean) for more information.

Parameters
hasFocus Boolean: Whether the window now has focus.

onWindowStartingActionMode

Added in API level 11
abstract fun onWindowStartingActionMode(callback: ActionMode.Callback!): ActionMode?

Called when an action mode is being started for this window. Gives the callback an opportunity to handle the action mode in its own unique and beautiful way. If this method returns null the system can choose a way to present the mode or choose not to start the mode at all. This is equivalent to onWindowStartingActionMode(android.view.ActionMode.Callback,int) with type ActionMode#TYPE_PRIMARY.

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

Added in API level 23
abstract fun onWindowStartingActionMode(
    callback: ActionMode.Callback!,
    type: Int
): ActionMode?

Called when an action mode is being started for this window. Gives the callback an opportunity to handle the action mode in its own unique and beautiful way. If this method returns null the system can choose a way to present the mode or choose not to start the mode at all.

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