Package icyllis.modernui.widget
Class PopupMenu
java.lang.Object
icyllis.modernui.widget.PopupMenu
-
Nested Class Summary
Nested ClassesModifier 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
ConstructorsConstructorDescriptionConstructor to create a new popup menu with an anchor view.Constructor to create a new popup menu with an anchor view and alignment gravity.PopupMenu
(Context context, View anchor, int gravity, ResourceId popupStyleAttr, ResourceId popupStyleRes) Constructor to create a new popup menu with a specific style. -
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:
context
- Context the popup menu is running in, through which it can access the current theme, resources, etc.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.
-
PopupMenu
public PopupMenu(Context context, View anchor, int gravity, @AttrRes ResourceId popupStyleAttr, @StyleRes ResourceId popupStyleRes) Constructor to create a new popup menu with a specific style.- Parameters:
context
- Context the popup menu is running in, through which it can access the current theme, resources, etc.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.popupStyleAttr
- An attribute in the current theme that contains a reference to a style resource that supplies default values for the popup window. Can be null to not look for defaults.popupStyleRes
- A resource identifier of a style resource that supplies default values for the popup window, used only if popupStyleAttr is null or can not be found in the theme. Can be null to not look for defaults.
-
-
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.
-