Package icyllis.modernui.widget
Class PopupMenu
java.lang.Object
icyllis.modernui.widget.PopupMenu
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Callback interface used to notify the application that the menu has closed.static interface
Interface responsible for receiving menu item click events if the items themselves do not have individual item click listeners. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
dismiss()
Dismiss the menu popup.Returns anView.OnTouchListener
that can be added to the anchor view to implement drag-to-open behavior.int
getMenu()
Returns theMenu
associated with this popup.Returns theListView
representing the list of menu items in the currently showing menu.void
setForceShowIcon
(boolean forceShowIcon) Sets whether the popup menu's adapter is forced to show icons in the menu item views.void
setGravity
(int gravity) Sets the gravity used to align the popup window to its anchor view.void
Sets a listener that will be notified when this menu is dismissed.void
Sets 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.
-
Constructor Details
-
PopupMenu
Constructor to create a new popup menu with an anchor view.- Parameters:
anchor
- Anchor view for this popup. The popup will appear below the anchor if there is room, or above it if there is not.
-
PopupMenu
Constructor to create a new popup menu with an anchor view and alignment gravity.- Parameters:
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
- TheGravity
value for aligning the popup with its anchor.
-
-
Method Details
-
setGravity
public void setGravity(int gravity) Sets the gravity used to align the popup window to its anchor view.If the popup is showing, calling this method will take effect only the next time the popup is shown.
- Parameters:
gravity
- the gravity used to align the popup window- See Also:
-
getGravity
public int getGravity()- Returns:
- the gravity used to align the popup window to its anchor view
- See Also:
-
getDragToOpenListener
Returns anView.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(myAnchor); myAnchor.setOnTouchListener(myPopup.getDragToOpenListener());
- Returns:
- a touch listener that controls drag-to-open behavior
-
getMenu
Returns theMenu
associated with this popup. Populate the returned Menu with items before callingshow()
.- Returns:
- the
Menu
associated with this popup - See Also:
-
show
public void show()Show the menu popup anchored to the view specified during construction.- See Also:
-
dismiss
public void dismiss()Dismiss the menu popup.- See Also:
-
setOnMenuItemClickListener
Sets a listener that will be notified when the user selects an item from the menu.- Parameters:
listener
- the listener to notify
-
setOnDismissListener
Sets a listener that will be notified when this menu is dismissed.- Parameters:
listener
- the listener to notify
-
setForceShowIcon
public void setForceShowIcon(boolean forceShowIcon) Sets whether the popup menu's adapter is forced to show icons in the menu item views.Changes take effect on the next call to show().
- Parameters:
forceShowIcon
-true
to force icons to be shown, orfalse
for icons to be optionally shown
-
getMenuListView
Returns theListView
representing the list of menu items in the currently showing menu.- Returns:
- The view representing the list of menu items.
-