Class MenuPopupHelper
- All Implemented Interfaces:
MenuHelper
-
Constructor Summary
ConstructorsConstructorDescriptionMenuPopupHelper(Context context, MenuBuilder menu) MenuPopupHelper(Context context, MenuBuilder menu, View anchorView) MenuPopupHelper(Context context, MenuBuilder menu, View anchorView, boolean overflowOnly, ResourceId popupStyleAttr) MenuPopupHelper(Context context, MenuBuilder menu, View anchorView, boolean overflowOnly, ResourceId popupStyleAttr, ResourceId popupStyleRes) -
Method Summary
Modifier and TypeMethodDescriptionvoiddismiss()Dismisses the popup, if showing.intgetPopup()booleanprotected voidCalled after the popup has been dismissed.voidsetAnchorView(View anchor) Sets the view to which the popup window is anchored.voidsetForceShowIcon(boolean forceShowIcon) Sets whether the popup menu's adapter is forced to show icons in the menu item views.voidsetGravity(int gravity) Sets the alignment of the popup window relative to the anchor view.voidvoidvoidshow()voidshow(int x, int y) booleantryShow()Attempts to show the popup anchored to the view specified bysetAnchorView(View).booleantryShow(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-trueto force icons to be shown, orfalsefor 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:
trueif the popup was shown or was already showing prior to calling this method,falseotherwise
-
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:
trueif the popup was shown or was already showing prior to calling this method,falseotherwise
-
dismiss
public void dismiss()Dismisses the popup, if showing.- Specified by:
dismissin 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()
-