I'm trying to create a custom popup menu that I would like to position on the overflow menu button of the actionbar (am using a Toolbar
with setSupportActionBar()
for this if it matters). I found out that this can be done with the setAnchorView()
(from reading Custom Menu item in Overflow menu).
However I cant seem to figure out how to retrieve the overflow menu as a view (that I could use to set the anchor with).
Also I did try anchoring this to the parent layout of the activity itself but it showed up on the left top, and the height of the menu was equal to the height of the actionbar (which is not very useful).
Does anyone know how this can be achieved?
Instead of having an actual overflow menu you could "cheat" a little bit. Have an icon in your actionbar that looks like the overflow icon. You should set showAsAction
to always on this MenuItem
. OnClick of the overflow icon, you show a ListPopupWindow
that's anchored to the MenuItem
view. If the ListPopupWindow
doesn't show up where you want it to, you can call ListPopupWindow.setHorizontalOffset()
and ListPopupWindow.setVerticalOffset()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With