public class MenuPopupHelper extends Object
Constructor and Description |
---|
MenuPopupHelper(Context context,
MenuBuilder menu) |
MenuPopupHelper(Context context,
MenuBuilder menu,
View anchorView) |
MenuPopupHelper(Context context,
MenuBuilder menu,
View anchorView,
boolean overflowOnly,
int popupStyleAttr) |
MenuPopupHelper(Context context,
MenuBuilder menu,
View anchorView,
boolean overflowOnly,
int popupStyleAttr,
int popupStyleRes) |
Modifier and Type | Method and Description |
---|---|
void |
dismiss()
Dismisses the popup, if showing.
|
int |
getGravity() |
android.support.v7.view.menu.MenuPopup |
getPopup() |
boolean |
isShowing() |
protected void |
onDismiss()
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 |
setOnDismissListener(PopupWindow.OnDismissListener listener) |
void |
setPresenterCallback(MenuPresenter.Callback cb) |
void |
show() |
void |
show(int x,
int y) |
boolean |
tryShow()
Attempts to show the popup anchored to the view specified by
setAnchorView(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.
|
public MenuPopupHelper(@NonNull Context context, @NonNull MenuBuilder menu)
public MenuPopupHelper(@NonNull Context context, @NonNull MenuBuilder menu, @NonNull View anchorView)
public MenuPopupHelper(@NonNull Context context, @NonNull MenuBuilder menu, @NonNull View anchorView, boolean overflowOnly, @AttrRes int popupStyleAttr)
public void setOnDismissListener(@Nullable PopupWindow.OnDismissListener listener)
public void setAnchorView(@NonNull View anchor)
Changes take effect on the next call to show().
anchor
- the view to which the popup window should be anchoredpublic void setForceShowIcon(boolean forceShowIcon)
Changes take effect on the next call to show().
forceShowIcon
- true
to force icons to be shown, or
false
for icons to be optionally shownpublic void setGravity(int gravity)
Changes take effect on the next call to show().
gravity
- alignment of the popup relative to the anchorpublic int getGravity()
public void show()
public void show(int x, int y)
@NonNull public android.support.v7.view.menu.MenuPopup getPopup()
public boolean tryShow()
setAnchorView(View)
.true
if the popup was shown or was already showing prior to calling this
method, false
otherwisepublic boolean tryShow(int x, int y)
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 is Gravity.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.
x
- x coordinate relative to the anchor viewy
- y coordinate relative to the anchor viewtrue
if the popup was shown or was already showing prior
to calling this method, false
otherwisepublic void dismiss()
protected void onDismiss()
Note: Subclasses should call the super implementation
last to ensure that any necessary tear down has occurred before the
listener specified by #setOnDismissListener(OnDismissListener)
is called.
public boolean isShowing()
public void setPresenterCallback(@Nullable MenuPresenter.Callback cb)