皮肤选项菜单 Android
我正在尝试在 Android 上设置选项菜单的皮肤。我使用自定义主题更改了背景颜色,但由于某种原因无法更改文本颜色。
我的主题
<style name="default" parent="@android:style/Theme.NoTitleBar">
<!-- Menu panel colors -->
<item name="android:panelBackground">@color/optionsMenuBackgroundColor</item>
<item name="android:panelFullBackground">@color/optionsMenuBackgroundColor</item>
<!-- Menu item colors -->
<item name="android:itemTextAppearance">@style/OptionsMenuFont</item>
</style>
我的选项菜单字体样式
<style name="OptionsMenuFont" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">@drawable/menu_item_font</item>
</style>
我的按钮颜色选择器的可绘制菜单_item_font.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Put other state colors up top -->
<item android:color="@color/optionsMenuTextColor" />
</selector>
该颜色只是十六进制颜色 #c4c4c4
我在这里缺少什么?
I'm trying to skin the options menu on android. I have the background color changed with a custom theme, but I can't get the text color to change for some reason.
My Theme
<style name="default" parent="@android:style/Theme.NoTitleBar">
<!-- Menu panel colors -->
<item name="android:panelBackground">@color/optionsMenuBackgroundColor</item>
<item name="android:panelFullBackground">@color/optionsMenuBackgroundColor</item>
<!-- Menu item colors -->
<item name="android:itemTextAppearance">@style/OptionsMenuFont</item>
</style>
My Style for the options menu font
<style name="OptionsMenuFont" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">@drawable/menu_item_font</item>
</style>
My drawable for the button color selector menu_item_font.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Put other state colors up top -->
<item android:color="@color/optionsMenuTextColor" />
</selector>
That color is just a hex color #c4c4c4
What am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以更改文本颜色,但它应该位于 textColor 标签下。您不能将可绘制对象放入任何 textColor 中(无论是在样式中,还是在布局中)。如果您想更改颜色,请将样式更改为:
You can change the text color but it should go under the textColor tag. You can't put a drawable in any textColor (neither in styles, nor in layouts). If you want to change the color, change your style to this:
这个问题已经以不同的方式被问过很多次了。使用 XML 布局,您可以更改背景颜色,但不能更改文本颜色:
http://code.google.com/p/android/issues/detail?id=4441
不过,您可以编写自定义类来完成菜单换肤操作:
http://www.techjini.com/博客/自定义背景和文本颜色在选项菜单-android/
This question has been asked in different ways a number of times. With XML layouts, you CAN change the background Color, but can NOT change the text color:
http://code.google.com/p/android/issues/detail?id=4441
You can, however, write a custom class to accomplish skinning the menu:
http://www.techjini.com/blog/customizing-background-and-text-color-in-options-menu-android/