Detailed explanation of how Android textview uses spannablestring to set compound text

This article illustrates how Android textview uses spannablestring to set compound text. Share with you for your reference, as follows:

Textview is usually used to display ordinary text, but sometimes it is necessary to set the style and event of some of the text. The Android system processes the specified text through the spannablestring class, which has the following functions:

1. Backgroundcolorspan background color 2. Clickablespan text can be clicked, with click events 3. Foregroundcolorspan text color (foreground color) 4. Maskfilterspan decoration effects, such as blurmaskfilter and embossmaskfilter 5. Metricaffectingspan parent class, which is generally not used 6. Rasterizerspan raster effect 7. Strikethrough span delete line (middle dash) 8. Suggestionspan is equivalent to placeholder 9, underlinespan underline 10, absolutesizespan absolute size (text font) 11 and dynamicdrawablespan to set the picture based on the text baseline or bottom alignment. 12. Imagespan picture 13. Relativesizespan relative size (text font) 14. Replacementspan parent class, generally not used 15. Scalexspan scales based on X-axis 16. Stylespan font styles: bold, italic, etc. 17. Subscriptspan subscript (mathematical formula will be used) 18. Superscript (mathematical formula will be used) 19. Textappearancespan text appearance (including font, size, style and color) 20, typefacespan text font 21, urlspan text hyperlink

Details are as follows:

1. Backgroundcolorspan background color

2. Clickablespan text can be clicked, and there are click events

View: Android uses textview to implement underlined hyperlinks

3. Foregroundcolorspan text color (foreground color)

4. Maskfilterspan decoration effects, such as blurmaskfilter and embossmaskfilter

PS: from the renderings, the relief effect is not obvious. You can see more clearly by setting the font larger. If you need other effects, you can inherit maskfilter to customize.

6. Rasterizerspan raster effect

PS: not clear at the moment, the effect is not obvious.

7. Strikethrough span strikethrough (DASH)

8、SuggestionSpan

It is equivalent to a placeholder and is generally used in the EditText input box. When you double-click this text, a prompt box will pop up to select some suggested (recommended) text, and the selected text will replace this placeholder. It is used more in input method.

PS: API 14 is newly added. There is no example yet.

9. Underlinespan underline

10. Absolutesizespan absolute size (text font)

PS: set the font size to a larger size for a strong effect.

11. Dynamicdrawablespan sets the picture to align based on the text baseline or bottom.

PS: the left picture is aligned based on the baseline, and the right picture is aligned based on the bottom

12. Imagespan pictures

PS: it is not different from dynamic drawablespan

13. Relativesizespan relative size (text font)

PS: the relative size scale is based on the current text font size

15. Scalexspan scales based on the X axis

16. Stylespan font style: bold, italic, etc

17. Subscriptspan subscript (used in mathematical formula)

18. Superscript span superscript (used in mathematical formula)

19. Textappearance span text appearance (including font, size, style and color)

PS: the system also provides the related value textappearance_ Small,TextAppearance_ Large et al. If necessary, it can be modified based on the above style.

20. Typefacespan text font

PS: how to use custom font settings will be described later

21. Urlspan text hyperlink

More readers interested in Android related content can view the special topics of this site: introduction and advanced tutorial of Android development, summary of Android multimedia operation skills (audio, video, recording, etc.), summary of Android basic components usage, summary of Android view technology, summary of Android layout skills and summary of Android control usage

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>