Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing default text colour and still showing disabled menu items in different colour

With Theme.Holo.Light as the base theme, a designer noticed that the default text colour is not black, but a dark grey (#505050). We'd like to change it to black.

enter image description here

Looking for a simple way to change the default to black everywhere in the app, I found that this works:

<resources>    
    <style name="MyAppTheme" parent="android:Theme.Holo.Light">
        <item name="android:textColor">@android:color/black</item>
    </style>
</resources>

Now, problem is, that also changes the colour of disabled items in Action Bar's overflow menu. How to override default text colour while still having disabled menu items look "disabled"?

The menu should look something like below, but using android:textColor as above, it changes all the items to black.

enter image description here

I was experimenting with textColorPrimaryInverse, textColorPrimaryDisableOnly, textColorPrimaryInverseDisableOnly and disabledAlpha but those didn't seem to affect the overflow menu.

like image 572
Jonik Avatar asked Dec 15 '22 02:12

Jonik


1 Answers

You can use a drawable as the text colour, and in drawable you can use selector to select the colour according to enabled status. Using following drawable definition as colour will make your disabled menu items grey and the rest black.

In e.g. res/drawable/default_text_colour.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:color="@android:color/darker_gray"/>
    <item android:color="@android:color/black"/>
</selector>

Then, using the drawable:

<item name="android:textColor">@drawable/default_text_colour</item>
like image 57
Antti Avatar answered Dec 31 '22 03:12

Antti