皮肤选项菜单 Android

发布于 2025-01-06 18:07:27 字数 1149 浏览 3 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初见你 2025-01-13 18:07:27

您可以更改文本颜色,但它应该位于 textColor 标签下。您不能将可绘制对象放入任何 textColor 中(无论是在样式中,还是在布局中)。如果您想更改颜色,请将样式更改为:

<style name="OptionsMenuFont" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
    <item name="android:textColor">#c4c4c4</item>
</style>

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:

<style name="OptionsMenuFont" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
    <item name="android:textColor">#c4c4c4</item>
</style>
苄①跕圉湢 2025-01-13 18:07:27

这个问题已经以不同的方式被问过很多次了。使用 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文