Share the post "How To Change The Preference Title Color In Android"
The Material Design of Android Lollipop has made it easier for developers to customize the theme of their apps. However, making it compatible for pre-Lollipop devices still has its limitations.
I tried to change the preference title color by using textColorPrimary and it did not work. So I had to do it programmatically.
There are two ways to do this. If you have any custom class that extends Preference, then you can add this code in the onBindView() method.
|
1 2 3 4 5 |
@Override protected void onBindView(View view) { ((TextView) view.findViewById(android.R.id.title)).setTextColor(Color.BLACK); super.onBindView(view); } |
If you are using the existing Preference class or even the CheckBoxPreference, you can do it this way:
|
1 2 3 |
Spannable title = new SpannableString(pref.getTitle().toString()); title.setSpan(new ForegroundColorSpan(Color.BLACK), 0, title.length(), 0); pref.setTitle(title); |
That should do the trick!