Class PopupMenu

java.lang.Object
icyllis.modernui.widget.PopupMenu

public class PopupMenu extends Object
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.
  • Constructor Details

    • PopupMenu

      public PopupMenu(Context context, View anchor)
      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

      public PopupMenu(Context context, View anchor, int gravity)
      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 - The Gravity 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

      public View.OnTouchListener getDragToOpenListener()
      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(myAnchor);
       myAnchor.setOnTouchListener(myPopup.getDragToOpenListener());
       
      Returns:
      a touch listener that controls drag-to-open behavior
    • getMenu

      public Menu getMenu()
      Returns the Menu associated with this popup. Populate the returned Menu with items before calling show().
      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

      public void setOnMenuItemClickListener(PopupMenu.OnMenuItemClickListener listener)
      Sets a listener that will be notified when the user selects an item from the menu.
      Parameters:
      listener - the listener to notify
    • setOnDismissListener

      public void setOnDismissListener(PopupMenu.OnDismissListener listener)
      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, or false for icons to be optionally shown
    • getMenuListView

      public ListView getMenuListView()
      Returns the ListView representing the list of menu items in the currently showing menu.
      Returns:
      The view representing the list of menu items.