10

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?

codeetcetera
  • 3,213
  • 4
  • 37
  • 62

2 Answers2

1

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>
Parmaia
  • 1,172
  • 1
  • 13
  • 28
Zinc
  • 1,002
  • 12
  • 18
0

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/

HalR
  • 11,411
  • 5
  • 48
  • 80
  • It doesn't work for me, I just get `IllegalStateException` because the factory has been set. – fikr4n Nov 25 '13 at 13:00
  • This is not true. You can change the text color by specifying it in your theme (styles.xml). – Luis Feb 03 '14 at 15:43