Android APIs
public class

PopupMenu

extends Object
java.lang.Object
   ↳ android.support.v7.widget.PopupMenu

Class Overview

Static library support version of the framework's PopupMenu. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.

Summary

Nested Classes
interface PopupMenu.OnDismissListener Callback interface used to notify the application that the menu has closed. 
interface PopupMenu.OnMenuItemClickListener Interface responsible for receiving menu item click events if the items themselves do not have individual item click listeners. 
Public Constructors
PopupMenu(Context context, View anchor)
Construct a new PopupMenu.
Public Methods
void dismiss()
Dismiss the menu popup.
Menu getMenu()
MenuInflater getMenuInflater()
void inflate(int menuRes)
Inflate a menu resource into this PopupMenu.
abstract void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing)
Called when a menu is closing.
abstract boolean onMenuItemSelected(MenuBuilder menu, MenuItem item)
Called when a menu item is selected.
abstract void onMenuModeChange(MenuBuilder menu)
Called when the mode of the menu changes (for example, from icon to expanded).
abstract boolean onOpenSubMenu(MenuBuilder subMenu)
Called when a submenu opens.
void setOnDismissListener(PopupMenu.OnDismissListener listener)
Set a listener that will be notified when this menu is dismissed.
void setOnMenuItemClickListener(PopupMenu.OnMenuItemClickListener listener)
Set a listener that will be notified when the user selects an item from the menu.
void show()
Show the menu popup anchored to the view specified during construction.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public PopupMenu (Context context, View anchor)

Construct a new PopupMenu.

Parameters
context Context for the PopupMenu.
anchor Anchor view for this popup. The popup will appear below the anchor if there is room, or above it if there is not.

Public Methods

public void dismiss ()

Dismiss the menu popup.

See Also

public Menu getMenu ()

Returns
  • the Menu associated with this popup. Populate the returned Menu with items before calling show().

public MenuInflater getMenuInflater ()

Returns
See Also

public void inflate (int menuRes)

Inflate a menu resource into this PopupMenu. This is equivalent to calling popupMenu.getMenuInflater().inflate(menuRes, popupMenu.getMenu()).

Parameters
menuRes Menu resource to inflate

public abstract void onCloseMenu (MenuBuilder menu, boolean allMenusAreClosing)

Called when a menu is closing.

public abstract boolean onMenuItemSelected (MenuBuilder menu, MenuItem item)

Called when a menu item is selected.

Parameters
menu The menu that is the parent of the item
item The menu item that is selected
Returns
  • whether the menu item selection was handled

public abstract void onMenuModeChange (MenuBuilder menu)

Called when the mode of the menu changes (for example, from icon to expanded).

Parameters
menu the menu that has changed modes

public abstract boolean onOpenSubMenu (MenuBuilder subMenu)

Called when a submenu opens. Useful for notifying the application of menu state so that it does not attempt to hide the action bar while a submenu is open or similar.

Parameters
subMenu Submenu currently being opened
Returns
  • true if the Callback will handle presenting the submenu, false if the presenter should attempt to do so.

public void setOnDismissListener (PopupMenu.OnDismissListener listener)

Set a listener that will be notified when this menu is dismissed.

Parameters
listener Listener to notify

public void setOnMenuItemClickListener (PopupMenu.OnMenuItemClickListener listener)

Set a listener that will be notified when the user selects an item from the menu.

Parameters
listener Listener to notify

public void show ()

Show the menu popup anchored to the view specified during construction.

See Also