I'm trying to display some colored text in my preference screen. To do so I'm creating a Spannable like this:
final String completeString = title + " - " + (TextUtils.isEmpty(currentValue) ? "?" : currentValue);
SpannableString span = new SpannableString(completeString);
span.setSpan(new ForegroundColorSpan(CURRENT_VALUE_COLOR), title.length() + 3, completeString.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
span.setSpan(new StyleSpan(Typeface.BOLD), title.length() + 3, completeString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
myPref.setSummary(span);
It works fine when my Preference is in the main PreferenceActivity screen, but when it's in a different PreferenceScreen then the color isn't displayed anymore
So for example it will work fine to change pref1 summary in that case:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="@string/cat1" >
<EditTextPreference
android:key="pref1"
android:summary="@string/pref1_summary"
android:title="@string/pref1_title" />
</PreferenceCategory>
</PreferenceScreen>
but it will fail in the following case:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="@string/cat1" >
<PreferenceScreen
android:summary="@string/prefSubScreen1" >
<ListPreference
android:key="pref1"
android:summary="@string/pref1_summary"
android:title="@string/pref1_title"
... />
Any idea how to make it work ?
Edit: In fact it looks like it has nothing to do with the Preference being in a different PreferenceScreen. It seems to fail in case of a ListPreference. Why are ListPreference failing to display a Spannable as their summary .