Look first.
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