Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set the android preference summary text color?

Tags:

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

like image 333
Sean Avatar asked Oct 23 '10 16:10

Sean


People also ask

How do I change the text color on my Android?

Open your device's Settings app . Text and display. Select Color correction. Turn on Use color correction.

Which property is used for text color in Android?

In XML, we can set a text color by the textColor attribute, like android:textColor="#FF0000" .


1 Answers

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 ForegroundColorSpan(color), 0, summary.length(), 0); preference.setSummary(summary); 
like image 85
Sean Avatar answered Sep 23 '22 21:09

Sean