An illustrated Android spannablestring

Source: Internet
Author: User

Look first.
    • In fact, a textview of the display content, how to do it?

Code implementation
TextView TV = (TextView) Findviewbyid (R. ID. Text_view);spannablestring ss = New Spannablestring (Red call italic strikethrough green underline Picture:. Blue background 1234567890abcdefghijklnopqrstuvwxyz ");Mark text with color SS. Setspan(New Foregroundcolorspan (Color. RED),0,2,//Setspan need to specify the flag,spanned. SPAN_exclusive_exclusive (not included before and after). Spanned. SPAN_exclusive_exclusive);Mark text SS with hyperlinks. Setspan(New Urlspan ("tel:10086"),2,5, spanned. SPAN_exclusive_exclusive);Mark text with Style (italic) SS. Setspan(New Stylespan (Typeface. BOLD_italic),5,7, spanned. SPAN_exclusive_exclusive);Mark text SS with strikethrough. Setspan(New Strikethroughspan (),7,Ten, spanned. SPAN_exclusive_exclusive);Mark the text SS with an underscore. Setspan(New Underlinespan (),Ten, -, spanned. SPAN_exclusive_exclusive);Mark SS with Color. Setspan(New Foregroundcolorspan (Color. GREEN),Ten, A, spanned. SPAN_exclusive_exclusive);Get drawable resource drawable d = getresources (). Getdrawable(R. drawable. IC_launcher);D. SetBounds(0,0D. Getintrinsicwidth(), D. Getintrinsicheight());Create Imagespan Imagespan span = new Imagespan (d, Imagespan. ALIGN_baseline);Replace text SS with Imagespan. Setspan(Span, -, +, spannable. SPAN_inclusive_exclusive);Mark text SS with blue background. Setspan(New Backgroundcolorspan (Color. BLUE), +, at, spannable. SPAN_exclusive_exclusive);With the zoomxTo Mark SS. Setspan(New Scalexspan (3), at, in, spannable. SPAN_exclusive_exclusive);Use superscript to mark SS. Setspan(New Superscriptspan (), in, *, spannable. SPAN_exclusive_exclusive);Use subscript to mark SS. Setspan(New Subscriptspan (), *, -, spannable. SPAN_exclusive_exclusive);Mark SS with relative size. Setspan(New Relativesizespan (3), -, +, spannable. SPAN_exclusive_exclusive);Many other//TODO//Text Settings TV. SetText(ss);
Reference links
    • Http://developer.android.com/reference/android/text/style/package-summary.html
    • http://blog.csdn.net/lovexjyong/article/details/17021235

An illustrated Android spannablestring

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.