The textColor attribute isn\'t working. Here\'s my XML:
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" />
Using Material Theme, you just have to override the following property :
<style name="YourTheme" parent="@style/Theme.MaterialComponents">
<item name="colorAccent">@color/your_custom_color</item>
</style>
Actually just found out that preference category text using colorAccent
.
If your app didn't using style of colorAccent
, you can go to styles.xml
and find <item name="colorAccent">@color/colorPrimary</item>
, and change the color as you want.
Other way around will be mention the theme in your AppTheme, application level
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
.....//your other items
<item name="preferenceTheme">@style/PrefTheme</item>
</style>
<style name="PrefTheme" parent="@style/PreferenceThemeOverlay">
<item name="preferenceCategoryStyle">@style/CategoryStyle</item>
</style>
<style name="CategoryStyle" parent="Preference.Category">
<item name="android:layout">@layout/pref_category_view</item>
</style>
XML : pref_category_view
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@android:id/title"
style="?android:attr/listSeparatorTextViewStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:textColor="@color/red"
android:layout_height="wrap_content"
/>
For more customization visit v7 Preferences res
Important: I am using PreferenceFragmentCompat from lib v7 Preference.
Define your own PreferenceTheme and override colors.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="preferenceTheme">@style/AppTheme.PreferenceTheme</item>
</style>
<style name="AppTheme.PreferenceTheme" parent="PreferenceThemeOverlay.v14.Material">
<item name="colorAccent">`#color_value`</item>
</style>