java.lang.Object | |
↳ | android.widget.PopupMenu |
A PopupMenu displays a Menu
in a modal popup window anchored to a View
.
The popup will appear below the anchor view if there is room, or above it if there is not.
If the IME is visible the popup will not overlap it until it is touched. Touching outside
of the popup will dismiss it.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
PopupMenu.OnDismissListener | Callback interface used to notify the application that the menu has closed. | ||||||||||
PopupMenu.OnMenuItemClickListener | Interface responsible for receiving menu item click events if the items themselves do not have individual item click listeners. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Construct a new PopupMenu.
| |||||||||||
Construct a new PopupMenu.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Dismiss the menu popup.
| |||||||||||
Returns an
View.OnTouchListener that can be added to the anchor view
to implement drag-to-open behavior. | |||||||||||
Inflate a menu resource into this PopupMenu.
| |||||||||||
Set a listener that will be notified when this menu is dismissed.
| |||||||||||
Set a listener that will be notified when the user selects an item from the menu.
| |||||||||||
Show the menu popup anchored to the view specified during construction.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface com.android.internal.view.menu.MenuBuilder.Callback | |||||||||||
From interface com.android.internal.view.menu.MenuPresenter.Callback |
Construct a new PopupMenu.
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. |
Construct a new PopupMenu.
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. |
gravity | The Gravity value for aligning the popup with its anchor
|
Returns an View.OnTouchListener
that can be added to the anchor view
to implement drag-to-open behavior.
When the listener is set on a view, touching that view and dragging outside of its bounds will open the popup window. Lifting will select the currently touched list item.
Example usage:
PopupMenu myPopup = new PopupMenu(context, myAnchor); myAnchor.setOnTouchListener(myPopup.getDragToOpenListener());
MenuInflater
that can be used to inflate menu items from XML into the
menu returned by getMenu()
.Inflate a menu resource into this PopupMenu. This is equivalent to calling popupMenu.getMenuInflater().inflate(menuRes, popupMenu.getMenu()).
menuRes | Menu resource to inflate |
---|
Set a listener that will be notified when this menu is dismissed.
listener | Listener to notify |
---|
Set a listener that will be notified when the user selects an item from the menu.
listener | Listener to notify |
---|
Show the menu popup anchored to the view specified during construction.