Android TextView Modify Text style

Source: Internet
Author: User



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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.