Class MenuPopupHelper
- All Implemented Interfaces:
MenuHelper
-
Constructor Summary
ConstructorDescriptionMenuPopupHelper
(Context context, MenuBuilder menu) MenuPopupHelper
(Context context, MenuBuilder menu, View anchorView) MenuPopupHelper
(Context context, MenuBuilder menu, View anchorView, boolean overflowOnly) -
Method Summary
Modifier and TypeMethodDescriptionvoid
dismiss()
Dismisses the popup, if showing.int
getPopup()
boolean
protected void
Called after the popup has been dismissed.void
setAnchorView
(View anchor) Sets the view to which the popup window is anchored.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 alignment of the popup window relative to the anchor view.void
void
void
show()
void
show
(int x, int y) boolean
tryShow()
Attempts to show the popup anchored to the view specified bysetAnchorView(View)
.boolean
tryShow
(int x, int y) Shows the popup menu and makes a best-effort to anchor it to the specified (x,y) coordinate relative to the anchor view.
-
Constructor Details
-
Method Details
-
setOnDismissListener
-
setAnchorView
Sets the view to which the popup window is anchored.Changes take effect on the next call to show().
- Parameters:
anchor
- the view to which the popup window should be anchored
-
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().
This method should not be accessed directly outside the framework, please use
PopupMenu.setForceShowIcon(boolean)
instead.- Parameters:
forceShowIcon
-true
to force icons to be shown, orfalse
for icons to be optionally shown
-
setGravity
public void setGravity(int gravity) Sets the alignment of the popup window relative to the anchor view.Changes take effect on the next call to show().
- Parameters:
gravity
- alignment of the popup relative to the anchor
-
getGravity
public int getGravity()- Returns:
- alignment of the popup relative to the anchor
-
show
public void show() -
show
public void show(int x, int y) -
getPopup
-
tryShow
public boolean tryShow()Attempts to show the popup anchored to the view specified bysetAnchorView(View)
.- Returns:
true
if the popup was shown or was already showing prior to calling this method,false
otherwise
-
tryShow
public boolean tryShow(int x, int y) Shows the popup menu and makes a best-effort to anchor it to the specified (x,y) coordinate relative to the anchor view.Additionally, the popup's transition epicenter (see
PopupWindow.setEpicenterBounds(Rect)
will be centered on the specified coordinate, rather than using the bounds of the anchor view.If the popup's resolved gravity is
Gravity.LEFT
, this will display the popup with its top-left corner at (x,y) relative to the anchor view. If the resolved gravity isGravity.RIGHT
, the popup's top-right corner will be at (x,y).If the popup cannot be displayed fully on-screen, this method will attempt to scroll the anchor view's ancestors and/or offset the popup such that it may be displayed fully on-screen.
- Parameters:
x
- x coordinate relative to the anchor viewy
- y coordinate relative to the anchor view- Returns:
true
if the popup was shown or was already showing prior to calling this method,false
otherwise
-
dismiss
public void dismiss()Dismisses the popup, if showing.- Specified by:
dismiss
in interfaceMenuHelper
-
onDismiss
protected void onDismiss()Called after the popup has been dismissed.Note: Subclasses should call the super implementation last to ensure that any necessary tear down has occurred before the listener specified by
setOnDismissListener(PopupWindow.OnDismissListener)
is called. -
isShowing
public boolean isShowing()
-