在溢出按钮锚弹出菜单 [英] anchor popup menu over overflow button

查看:157
本文介绍了在溢出按钮锚弹出菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个自定义弹出菜单,我想(我使用的是工具栏与<$ C $的动作条的溢出菜单按钮,定位C> setSupportActionBar()此,如果它事项)。我发现,这可能与 setAnchorView()(从阅读的在溢出菜单自定义菜单项)。

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?

推荐答案

。有一个看起来像溢图标在动作条的图标。你应该设置 showAsAction 来一直在这个菜单项。溢图标的OnClick,你表现出 ListPopupWindow 多数民众赞成固定在菜单项视图。如果你想要它,你可以调用 ListPopupWindow.setHorizo​​ntalOffset() ListPopupWindow 显示不出来 ListPopupWindow.setVerticalOffset()

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

这篇关于在溢出按钮锚弹出菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆