Home » Android » Change Preference Item Summary Text Color in Android 4

Change Preference Item Summary Text Color in Android 4

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have the below sample of preference items

 <CheckBoxPreference
     android:key="chkSound"
     android:summary="Sound is Off"
     android:title="Sound" />

I use a theme in the res/values to change the Summary text color

 <style name="ThemeDarkText">
    <item name="android:textColor">#000000</item>
  </style>

And in the code I write this line

    setTheme(R.style.ThemeDarkText);

Its working fine in Android 2.1 but when I tried to run it on a different os (ex Android 4.0)
It didn’t change the summary text color just the title color only..!!

Any help?

How to&Answers:

I had the same problem here.

What was interesting was that the summary of Edit Preference was colored properly – red, but the Checkbox and the PreferenceScreen were white.

This is my solution:

Add this to the style.xml in your theme:

<item name="android:textColorSecondary">@color/your_color</item>

Answer:

For those using Theme.AppCompat (Lollipop), this is controlled by

<item name="colorAccent">@color/accent</item>