Skip to content Skip to sidebar Skip to footer

Android Preferences Summary Default Color?

I have installed my app in a real phone, and even though in the emulator all the texts of the preferences summaries seem to be in the same color, in the real phone the color is dif

Solution 1:

Preference pUpdate = findPreference("sys_setting_update");
pUpdate.setSummary(Html.fromHtml("<font color=\"#B0C4DE\">This is content</font>"));

use Html.fromHtml("<font color=\"#B0C4DE\">This is content</font>") to setSummary

Solution 2:

I found these: android:textAppearance="?android:attr/textAppearanceLarge" and android:textAppearance="?android:attr/textAppearanceSmall" seem to do the trick.

Solution 3:

I have figured out a way to retrieve the default color used by the Android device your application is running in. It is a bit tricky and requieres that you retrieve the color being shown from another Preference Summary View of your activity and store it in runtime.

Then you can use the same color code in other Views of other preferences, assuring that you will allways get the same color code Android assigned to the standard preferences. Here is how I did it:

My preferences activity has a normal CheckBoxPreference that I use to activate or deactivate a service. I have extended CheckBoxPreference as follows, so my extension retrieves in rutime the default color Android finally gave to the summary of that CheckBoxPreference:

publicclassMyCheckBoxPreferenceextendsandroid.preference.CheckBoxPreference {

    privatestaticintsSummaryColor= Color.WHITE;
    privatestaticbooleansInitialized=false;

    publicMyCheckBoxPreference(Context context) {
        super(context);
    }

    publicMyCheckBoxPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    publicMyCheckBoxPreference(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @OverridepublicvoidonBindView(View view) {
        super.onBindView(view);
        if (!sInitialized) {
            sSummaryColor = getSummaryColor(view);
            sInitialized = true;
        }
    }

    privateintgetSummaryColor(View view) {

       intcolor= Color.WHITE;

        // Gets the color android gave to the summary by defaultTextViewsummaryView= (TextView) view.findViewById(android.R.id.summary); 
        if (summaryView != null) {
           ColorStateListlist= summaryView.getTextColors();
            if (list != null) {
                color = list.getDefaultColor();
            }
        }
        return color;
    }

    publicstaticintgetSummaryColor() {
        return sSummaryColor;
    }
}

In my preferences.xml I instantiate that preference as MyCheckBoxPreference instead of just CheckBoxPreference:

<org.yourpackage.MyCheckBoxPreference
                android:title="@string/preference_title_activate" 
                android:defaultValue="false" 
                android:summary="@string/preference_summary_activate_off" 
                android:summaryOff="@string/preference_summary_activate_off"
                android:key="preference_activate">
</org.yourpackage.MyCheckBoxPreference>

The MyCheckBoxPreference has to be instantiated once before retrieving the summary color with MyCheckBoxPreference.getSummaryColor().

Now you can set the color of other customized preferences from onBindView(View):

publicclassMyCustmizedPreferenceextendsPreference {
    publicMyCustmizedPreference(Context context) {
        super(context);
        setLayoutResource(R.layout.my_customized_preference);
    }

    @OverridepublicvoidonBindView(View view) {
        super.onBindView(view);

        TextViewsummaryView= (TextView) view.findViewById(android.R.id.summary);
        if (summaryView != null) {
            summaryView.setTextColor(MyCheckBoxPreference.getSummaryColor());
        }        
    }
}

It actually works under Samsung Galaxy S. I have also tested that it doesn't break anything under the emulator.

Solution 4:

The Samsung Galaxy S phones have their own Preference layout with the text color specified for the Summary line. Even though a TextAppearance.Small is specified the textColor attribute of the layout is overriding the text appearance.

Solution 5:

I don't think this is possible. I am able to change the background color and the title text color, but not the summary color.

Background:

getListView().setBackgroundColor(Color.TRANSPARENT);

Title text:

Preferenceyourpreference= findPreference("yourpreference");
TextViewtv= (TextView)yourpreference.getView(null, getListView());
tv.setTextColor(...);

Sorry I couldn't help more...

Post a Comment for "Android Preferences Summary Default Color?"