How to change text color of preference category in Android?

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.


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" />

An easy way to do this is to set the custom layout for the preferenceCategory here:

<PreferenceCategory
    android:layout="@layout/preferences_category"
    android:title="Privacy" >

Then set your code inside your preferences_category layout file:

<TextView
    android:id="@android:id/title"
    android:textColor="@color/deep_orange_500"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="16sp"
    android:textStyle="bold"
    android:textAllCaps="true"/>