1

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 .

user1026605
  • 1,633
  • 4
  • 22
  • 58

1 Answers1

0

You can add this theme in your style.xml

<style name="SettingsTheme" parent="EsimiBulPreferenceTheme">
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:colorAccent">@color/colorAccent</item>
    <item name="android:background">@color/mobwoo_color_comet</item>
    <item name="android:fontFamily">@font/raleway_regular</item>
    <item name="android:textColor">#FFFFFF</item>
</style>

and define this part in your Manifest.xml

 <activity
        android:name="com.smartral.mobwoo.activities.Activity_Settings"
        android:screenOrientation="portrait"
        android:theme="@style/SettingsTheme" />

it works for me.

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
John Error
  • 2,076
  • 5
  • 18
  • 23