Change listpreference Summary text color and size
Asked Answered
B

3

11

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

Bingaman answered 17/7, 2013 at 0:25 Comment(0)
T
12

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.

Tectonic answered 31/1, 2014 at 13:35 Comment(1)
Summary text uses 'android:textColorTertiary' or 'android:textColorSecondary' depending on the preference.Tarrance
J
2

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" />
Johanson answered 17/7, 2013 at 2:24 Comment(1)
i copy the link and create layout and past it on it the refer reference to it as you explain but its not workBingaman
H
2

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

    <item name="android:textColorSecondary">#00CC00</item>
Heliotropism answered 18/7, 2013 at 10:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.