views:

75

answers:

3

On my preference screen I have a preference that when clicked opens a color picker dialog. What I would like to do is when the user selects a color, that the text summary of the preference is displayed in that color.

I know I can have the summary set up like this, Currently <font color="#ff0000">this color</font> and have it display in that color. The problem is the color I am getting back is the android int color.

I could use the red(), green(), blue() methods and then convert those to Hex and then combine them into a string so I could set the summary text with the new value and that works: String colorString = String.format("#%02x%02x%02x",Color.red( defaultColor ), Color.green( defaultColor ), Color.blue( defaultColor )); I was just curious if there is an easier way to do this.

Thanks ahead of time.

Sean

A: 

The problem is the color I am getting back is the android int color

What is "the android int color"?

Generally, I try to put the color in ARGB format (#FFFF0000 for red, for example).

CommonsWare
The colorPickerDialog (taken from the API Examples) supplies the color as an int (how android stores it internally).
Sean
A: 

Hi you can change the color of preference using Html.fromHtml().

ex : private String title = "" + "Set the SMS Send Limit" + "";

and add set this string from your android application like this .

CheckBoxPreference _test = (CheckBoxPreference)findPreference("text"); _test .setTitle(Html.fromHtml(title ));

follow this link for html view of android : http://www.androidpeople.com/tag/html-tags/

Thanks

Sujit
I am aware of that. However, like I said above, I have access to the color as an int which is how Android stores it. Not the RGB or ARGB strings.
Sean
A: 

OK what I ended up doing was using a Spannable. This takes the color as an integer.

Spannable summary = new SpannableString ( "Currently This Color" );
summary.setSpan( new ForgroundColorSpan( color ), 0, summary.length(), 0 );
preference.setSummary( summary );
Sean