Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

anchor popup menu over overflow button

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?

like image 964
source.rar Avatar asked Mar 03 '15 14:03

source.rar


1 Answers

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()

like image 142
Andrew Orobator Avatar answered Oct 04 '22 04:10

Andrew Orobator