SpannableString for Android development and android Development
In the actual application development process, it is often encountered that different text parts display different font style information, such as text font, size, color, style, and hyperlink. In general, the text in TextView is a style. in similar cases, you can use the SpannableString or SpannableStringBuilder object to implement the above settings.
Both SpannableString and SpannableStringBuilder can set a text segment to a Span. In Android, Span represents the effect of a text segment, such as the link format, image, and background text. The difference is that SpannableStringBuilder can modify the text content.
Click it to get familiar with the SpannableString class.
Class Structure:
Extends Object
Implements GetChars Spannable CharSequence
Java. lang. Object |
Bytes |
Android. text. SpannableString |
Class Overview:
The content of such text remains unchanged, but the marking object can be appended and separated. For variable text, seeSpannableStringBuilder
.
Constructor:
Public Constructors |
|
SpannableString (CharSequence source) |
Common public methods:
Public Methods |
Final char |
CharAt (int I) Returns the character at the specified index position. The index of the first character is 0. |
Boolean |
Equals (Object o) Compares this instance with the specified object and indicates if they are equal. Compare this instance with the specified object. If it is equal, true is returned. |
Final void |
GetChars (int start, int end, char [] dest, int off) Similar to the String. getChars () method: copy characters from the specified character array. Start position, end position, and off offset. |
Int |
GetSpanEnd (Object what) Obtain the end position of what object in the SpannableString object. If no match exists,-1 is returned. |
Int |
GetSpanStart (Object what) Obtain the starting position of what object in the SpannableString object. If no match exists,-1 is returned. |
Final int |
Length () Returns the number of characters in the sequence. |
Void |
RemoveSpan (Object what) Deletes a specified object from the text range. |
Void |
SetSpan (Object what, int start, int end, int flags) Sets a Span object. What |
Note:
Void setSpan (Object what, int start, int end, int flags)
Sets a Span object. The first parameter "what" indicates the effect of a piece of text. It can accept the following attributes:
Attribute name |
Description |
BackgroundColorSpan |
Background Color |
ClickableSpan |
Clickable text with click events |
ForegroundColorSpan |
Text color (foreground color) |
MaskFilterSpan |
Blur (BlurMaskFilter) embossed (EmbossMaskFilter) |
MetricAffectingSpan |
Parent class, generally not used |
RasterizerSpan |
Grating effect |
StrikethroughSpan |
Strikethrough (hyphen) |
SuggestionSpan |
Equivalent to a placeholder |
UnderlineSpan |
Underline |
AbsoluteSizeSpan |
Absolute size (text font) |
DynamicDrawableSpan |
Set the image to align based on the text baseline or bottom. |
ImageSpan |
Image |
RelativeSizeSpan |
Relative size (text font) |
ReplacementSpan |
Parent class, generally not used |
ScaleXSpan |
Zooming based on X axis |
StyleSpan |
Font Style: bold and italic |
SubscriptSpan |
Subscript (used in mathematical formulas) |
SuperscriptSpan |
Superscript (used in mathematical formulas) |
TextAppearanceSpan |
Text appearance (including font, size, style, and color) |
TypefaceSpan |
Text font |
URLSpan |
Text hyperlink |
The second and third parameters indicate the start position and end position of a text segment to be set to Span, namely start and end. The last parameter (flags) is a flag. You can also set the following values:
Spanned. SPAN_EXCLUSIVE_INCLUSIVE: The Span effect is not applied to the characters entered before the Span, and the Span effect is applied to the characters entered later.
Spanned. SPAN_INCLUSIVE_EXCLUSIVE: Apply the Span effect to the character entered before the Span, and do not apply the Span effect to the character entered after the Span.
Spanned. SPAN_INCUJSIVE_INCLUSIVE: Apply the Span effect to all the characters entered before and after the Span.
Application instance:
For details about SpannableString, refer to TextView advanced application for Android development.
Android Application Development details: what is written in this book? Which android sdk version is used in the book?
I have read that it is a very easy-to-understand book for beginners. The basic plug-in usage methods and various functions are well described and recommended.
Do you have any suggestions for registering a security officer during an interview with Foxconn?
INTERVIEW TIPS
Aquarius is both an alternative and good at being funny. When applying for and choosing a job, it will unconsciously work in the creative industry. Its novel and distinctive clothes may make these companies look strange and conform to the expectations of the other party. However, when talking about Aquarius, it is easy to fall into extreme ideas and comments, but it will scare the other party. It is recommended that Aquarius wear a balanced and perfect white crystal. Besides, white crystal, also known as Guan yunshi, can help your work!