[Go] details about attributes of spannablestring

Source: Internet
Author: User

1. backgroundcolorspan background color
2. clickablespan text clickable, with click events
3. foregroundcolorspan text color (foreground color)
4. maskfilterspan modifier effects, such as blurmaskfilter and embossmaskfilter)
5. metricaffectingspan parent class, generally not used
6. rasterizerspan grating effect
7. strikethroughspan strikethrough)
8. suggestionspan is equivalent to a placeholder
9. underlinespan underline
10. absolutesizespan absolute size (text font)
11. Set the Image Based on the text baseline or bottom alignment in dynamicdrawablespan.
12. imagespan Image
13. Relative relativesizespan size (text font)
14. replacementspan parent class, generally not used
15. scalexspan scales based on the X axis
16. stylespan Font Style: bold and italic
17. subscriptspan subscript (used in mathematical formulas)
18. superscriptspan tagging (used in mathematical formulas)
19. textappearancespan text appearance (including font, size, style, and color)
20. typefacespan text font

21. urlspan text hyperlink

 

 

 

Backgroundcolorspan background color

 

Spannablestring spantext = new spannablestring ("benzlocke ");

 

Spantext. setspan (New backgroundcolorspan (color. Green), 0, spantext. Length (),

 

Spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );




Foregroundcolorspan text color (foreground color)

 

Spantext = new spannablestring ("benzlocke ");

 

Spantext. setspan (New foregroundcolorspan (color. Blue), 6, spantext. Length (),

 

Spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );




Maskfilterspan modifier effects, such as blurmaskfilter and embossmaskfilter)

 

Spantext = new spannablestring ("benzlocke ");

 

Int length = spantext. Length ();

 

// Blurmaskfilter)

 

Maskfilterspan = new maskfilterspan (New blurmaskfilter (3, blur. Outer ));

 

Spantext. setspan (maskfilterspan, 0, length-10, spannable.

 

Span_inclusive_exclusive );

 

// Embossmaskfilter)

 

Maskfilterspan = new maskfilterspan (New embossmaskfilter (new float [] {1, 1, 3}, 1.5f, 8, 3 ));

 

Spantext. setspan (maskfilterspan, length-10, length, spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );



Rasterizerspan grating effect

 

Spantext = new spannablestring ("strikethroughspan ");

 

Spantext. setspan (New strikethroughspan (), 0, 7, spannable.

 

Span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );



Strikethroughspan strikethrough

 

Spantext = new spannablestring ("strikethroughspan ");

 

Spantext. setspan (New strikethroughspan (), 0, 7, spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );



Suggestionspan

 

It is equivalent to a placeholder and is generally used in the edittext input box. When you double-click the text, a prompt box will pop up to select some recommended text. The selected text will replace the placeholder. Most of the input methods are used.



Underlinespan underline

 

Spantext = new spannablestring ("underlinespan ");

 

Spantext. setspan (New underlinespan (), 0, spantext. Length (),

 

Spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );



Absolutesizespan absolute size (text font)

 

Spantext = new spannablestring ("absolutesizespan ");

 

Spantext. setspan (New absolutesizespan (20, true), 0, spantext. Length (),

 

Spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );



Dynamicdrawablespan sets the Image Based on the text baseline or bottom alignment.

 

Dynamicdrawablespan drawablespan = new dynamicdrawablespan (dynamicdrawablespan. align_baseline ){

 

@ Override

 

Public drawable getdrawable (){

 

Drawable d = getresources (). getdrawable (R. drawable. ic_launcher );

 

D. setbounds (0, 0, 50, 50 );

 

Return D;

 

}

 

};

 

Dynamicdrawablespan drawablespan2 = new dynamicdrawablespan (

 

Dynamicdrawablespan. align_bottom ){

 

@ Override

 

Public drawable getdrawable (){

 

Drawable d = getresources (). getdrawable (R. drawable. ic_launcher );

 

D. setbounds (0, 0, 50, 50 );

 

Return D;

 

}

 

};

 

Spantext. setspan (drawablespan, 3, 4, spannable. span_inclusive_exclusive );

 

Spantext. setspan (drawablespan2, 7, 8, spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );

 

// Align the left image with the baseline, and align the right image with the bottom image.



Imagespan Image

 

Spantext = new spannablestring ("imagespan ");

 

Drawable d = getresources (). getdrawable (R. drawable. ic_launcher );

 

D. setbounds (0, 0, 50, 50 );

 

Spantext. setspan (New imagespan (d), 3, 4, spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );

 

// It is slightly different from dynamicdrawablespan.



Relative size of relativesizespan (text font)

 

Spantext = new spannablestring ("relativesizespan ");

 

// Parameter proportion: proportional size

 

Spantext. setspan (New relativesizespan (2.5f), 3, 4,

 

Spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );

 

// The relative size ratio is based on the current text font size.



Scalexspan scales based on the X axis

 

Spantext = new spannablestring ("benzlocke ");

 

// Parameter proportion: proportional size

 

Spantext. setspan (New scalexspan (3.8f), 3, 7, spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );



Stylespan Font Style: bold and italic

 

Spantext = new spannablestring ("benzlocke ");

 

// Typeface. bold_italic: bold + Italic

 

Spantext. setspan (New stylespan (typeface. bold_italic), 3, 7,

 

Spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );



Subscriptspan subscript (used in mathematical formulas)

 

Spantext = new spannablestring ("benzlocke ");

 

Spantext. setspan (New subscriptspan (), 6, 7, spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );



Superscriptspan superscript (used in mathematical formulas)

 

Spantext = new spannablestring ("benzlocke ");

 

Spantext. setspan (New superscriptspan (), 6, 7, spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );



Textappearancespan text appearance (including font, size, style, and color)

 

Spantext = new spannablestring ("benzlocke ");

 

// To customize textappearance, you can modify the system style.

 

Spantext. setspan (New textappearancespan (this, Android. R. style. textappearance_medium), 6, 7, spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );

 

// The system also provides related values such as textappearance_small and textappearance_large. You can modify the above style as needed.



Typefacespan text font

 

Spantext = new spannablestring ("benzlocke ");

 

// If you need to use a Custom font, you may need to override the typefacespan class.

 

Spantext. setspan (New typefacespan ("monospace"), 3, 10,

 

Spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );

 

// For settings of custom fonts, the following describes how to use



Urlspan text hyperlink

 

Spantext = new spannablestring ("benzlocke ");

 

Spantext. setspan (New urlspan ("http://orgcent.com"), 10, spantext. Length (),

 

Spannable. span_inclusive_exclusive );

 

Mtvtext. append ("\ n ");

 

Mtvtext. append (spantext );

 

// Enable urlspan to click

 

Mtvtext. setmovementmethod (New linkmovementmethod ());
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.