Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change text color of preference category in Android?

The textColor attribute isn't working. Here's my XML:

<PreferenceCategory         android:title="Title"         android:textColor="#00FF00"> 

Any ideas?

like image 617
Michael Eilers Smith Avatar asked Jul 23 '12 06:07

Michael Eilers Smith


People also ask

How do I set background preferences?

Go to res>values>styles. xml> and add this code to your <style > </style> the style should must be app base theme in this @color/activ is color resources added to colors. Show activity on this post. I am using the PreferenceFragmentCompat, the below solution worked for me.

What is preference framework in Android?

What is the Preferences Framework? Android system provides many ways to save data for your application. One of them is Preferences Framework , through Android preference framework we can easily develop screen that allows user to modify preferences.


2 Answers

use this customize PreferenceCategory class :

public class MyPreferenceCategory extends PreferenceCategory {     public MyPreferenceCategory(Context context) {         super(context);     }      public MyPreferenceCategory(Context context, AttributeSet attrs) {         super(context, attrs);     }      public MyPreferenceCategory(Context context, AttributeSet attrs,             int defStyle) {         super(context, attrs, defStyle);     }      @Override     protected void onBindView(View view) {         super.onBindView(view);         TextView titleView = (TextView) view.findViewById(android.R.id.title);         titleView.setTextColor(Color.RED);     } } 

and add this at your Pref.xml file :

<ali.UI.Customize.MyPreferenceCategory android:title="@string/pref_server" /> 
like image 103
AliSh Avatar answered Oct 17 '22 05:10

AliSh


One solution is to make a theme for your PreferenceScreen. So in your themes.xml or styles.xml (better to put it in themes.xml) :

<style name="PreferenceScreen" parent="YourApplicationThemeOrNone">     <item name="android:textColor">@color/yourCategoryTitleColor</item> </style> 

then in your AndroidManifest.xml :

<activity       android:name="MyPreferenceActivity"       ...       android:theme="@style/PreferenceScreen" > </activity> 

It worked perfectly for me.

like image 30
flawyte Avatar answered Oct 17 '22 06:10

flawyte