First, the charsequence interface
Textview.settext (charsequence);
second, realize Charsequence interface
Spannablestring, Spannablestringbuilder implements this interface, but what is the difference between the two?
Iii. Examples
String Text = "Love_world_";
spannablestring style = new spannablestring (text);
Style.setspan (New Foregroundcolorspan (color.red), 0,5,spannable.span_exclusive_inclusive);
Textview.settext (style);
four, spannable interface capability
spannablestring, Spannablestringbuilder These two classes also implement Spannable interface, according to the above example, view the next Spannable.setspan method
Public void Setspan (Object, int start, int end, int flags);
This method has 4 parameters, where the second and third are the starting and ending positions of the text in the string where the style needs to be set.
The following focus on the first parameter, when receiving objects, object, all of its supported styles can be queried in the official document http://developer.android.com/reference/android/text/style/ Package-summary.html
most of them are for API level 1, only API level 14 new Easyeditspan, Suggestionspan, API level 17 new Localespan, API level 21 new TTSSP an
Foregroundcolorspan Specifies that the text color passed in the parameter has the following four kinds of wording, which needs to notice is the first way 0x must immediately follow two FF to express the transparency, does not resolve to 00 that is transparent does not see the effect.
new Foregroundcolorspan (0XFFEEEEEE)//must have FF transparency value
New Foregroundcolorspan (Color. Parsecolor ("#eeeeee"))
new Foregroundcolorspan (color.red)
New Foregroundcolorspan (Getresources (). GetColor (r.color.name))
font Typefacespan, add strikethrough strikethroughspan, set font Typefacespan
References:
http://blog.csdn.net/hitlion2008/article/details/6856780
Android TextView Modify Text style