Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change listpreference Summary text color and size

I have listpreference in my app , i want to customize it , i can set theme to prefs activity as bellow :

 <activity 
     android:name=".Prefs" 
     android:label="@string/app_name" 
     android:theme="@style/PreferencesTheme">

preference style:

<?xml version="1.0" encoding="utf-8" ?> 
<resources xmlns:android="http://schemas.android.com/apk/res/android">
 <style name="PreferencesTheme" parent="android:Theme">
 <item name="android:background">#FFDAB9</item> 
 <item name="android:textColor">@color/red_color</item> 
 <item name="android:textSize">20sp</item> 
</style>
</resources>

The above style changes the ListPreference background and ListPreference title text size and text color BUT it doesn't change ListPreference summary text color or size any way to do that ,

i tried this code but it doesn't work:

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

any help will be appreciated, thanks

like image 763
androidqq6 Avatar asked Jul 17 '13 00:07

androidqq6


3 Answers

Maybe it's too late to answer, but try to remove your line of color:

<item name="android:textColor">@color/red_color</item>

And add this which are for the primary, secondary and tertiary colors

<item name="android:textColorPrimary">@color/red_color</item>
<item name="android:textColorSecondary">@color/red_color</item>
<item name="android:textColorTertiary">@color/red_color</item>

You can choose the color you want to all those, honestly, I never saw the tertiary color in any preference page, but the primary is for the main and big text, the secondary is for the small text appears below the primary.

Hope it helps.

like image 135
Minion Avatar answered Sep 30 '22 05:09

Minion


That sucks because the xml file says it uses textColorSecondary for the summary color.

What I would recommend you do is copy and save the contents of the file above into your own project, edit that file to look the way you want it to (Remember not to change any ids), and display a custom list preference item layout.

You can apply a custom preference layout in xml like so:

<ListPreference
    android:key="pref_key"
    android:title="@string/my_list_preference"
    android:layout="@layout/custom_list_preference" />
like image 22
jimmithy Avatar answered Sep 30 '22 06:09

jimmithy


I put this line into styles.xml and it works:

    <item name="android:textColorSecondary">#00CC00</item>
like image 43
HAL9000 Avatar answered Sep 30 '22 07:09

HAL9000