ActionBar 上特定菜单项的不同外观/样式
在我的 Android 应用程序上,我按照 android 开发人员的提示自定义 ActionBar博客和其他地方。我希望能够突出显示 ActionBar 上的特定菜单项,例如使用不同的背景颜色,因为它特别适用于当前可见的片段(实际上添加了它)。然而,我还没有发现任何迹象表明可以做到这一点,我自己也还没有设法做到这一点。是否可以?如果是这样怎么办?
On my Android application I am customizing the ActionBar following tips from the android developer blog and other places. I would like to be able to highlight a specific menu item on the ActionBar e.g. with a different background color because it is especially applicable to a currently visible fragment (which actually added it). However I have not found any indication that this can be done nor have I managed to do so myself yet. Is it possible? If so how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我现在通过一些技巧让它发挥作用。这里是片段代码
主要问题是 onclicklistener 必须设置在您设置为操作视图的视图上,而不是菜单项上才能使其工作。这样你就可以做任何你喜欢做的事。
另请注意,您不能使用 getActionView 检索最初设置的带有标题的视图,因为它将返回 null。它似乎更像是一种替代视图,而不是默认菜单项的实际视图。
So I got this to work now with a bit of a trick to it. Here goes the fragment code
The main gotcha is that the onclicklistener has to be set on the view that you set as action view and not the menu item for it to work. This way you can do whatever you like.
Also note that you can NOT use getActionView to retrieve the originally set view with title because it will return null. It seem to be more of an alternative view than the actual view for default menu items..