Android 菜单项背景
我想更改菜单项背景,因为我使用黑色图标,但在某些手机上,背景的默认颜色是黑色或其他深色。我尝试了 这个解决方案并且它有效,但有一个小问题: 我有十个项目,这就是为什么我有一个“更多”项目来显示其他选项,但如果我选择“更多”项目(具有自定义背景),然后按后退按钮,该项目将处于默认状态,默认颜色。解决办法是什么?谢谢!
I want to change the menu item background beacuse I use black icons, but on some phones the default color of background is black or other dark color. I tried this solution and it's worked but there was a little problen with it:
I have ten items and that's why I have a "More" item to show other options, but if I choose the More item (which is got the custom background) and after that I press back button, the item will be in the default state, default colors. What is the solution? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
菜单背景的样式属性是
android:panelFullBackground
。它不像其他解决方案那样黑客,所以它没有那么有问题。不管文档怎么说,它必须是一个资源(例如
@android:color/black
或@drawable/my_drawable
),如果您使用颜色值,它会崩溃直接地。The style attribute for the menu background is
android:panelFullBackground
. It's not hackish like the other solution, so it's not as buggy.Despite what the documentation says, it needs to be a resource (e.g.
@android:color/black
or@drawable/my_drawable
), it will crash if you use a color value directly.尝试使用 android 自己的菜单图标,如 setIcon(android.R.drawable.ic_menu_search)
try to use android own menu icon like as setIcon(android.R.drawable.ic_menu_search)