Spannable reduces TextView splicing and adds text hyperlinks to the font color, background color, font size, and style of some texts in a string.
For example, change some fonts to Red:
SpannableString amountS = new SpannableString (amount );
AmountS. setSpan (new ForegroundColorSpan (Color. RED), amount. indexOf (orderInfo. PayMoney + ""), amount. indexOf ("") + 1, Spannable. span_exclusive_random SIVE );
The following describes what and flags parameters in setSpan:
SetSpan (Object what, int start, int end, int flags)
1. what is an Object mainly used to set the attributes, sizes, colors, and background colors of text:
BackgroundColorSpan, ClickableSpan, ForegroundColorSpan, MaskFilterSpan, MetricAffectingSpan,
RasterizerSpan, StrikethroughSpan, SuggestionSpan, UnderlineSpan
Detailed description:
BackgroundColorSpan: Background Color
ClickableSpan
ForegroundColorSpan changes the color of the text font
MaskFilterSpan (MaskFilter filter) modifier, such as BlurMaskFilter and EmbossMaskFilter)
MetricAffectingSpan
Subclass: AbsoluteSizeSpan, LocaleSpan, RelativeSizeSpan, ReplacementSpan, ScaleXSpan, StyleSpan, SubscriptSpan, SuperscriptSpan, TextAppearanceSpan, TypefaceSpan
Indirect subclass: DynamicDrawableSpan, ImageSpan
RasterizerSpan grating effect
StrikethroughSpan strikethrough)
SuggestionSpan placeholder
UnderlineSpan underline
ImageSpan image package. You can add an image to a text clip.
SubscriptSpan subscript-used in mathematical formulas
SuperscriptSpan superscript-mathematical formula used
ScaleXSpan (3.8f) zooming based on X axis
StyleSpan (Typeface. BOLD_ITALIC) Font Style: bold, italic, etc.
TextAppearanceSpan (this, android. R. style. TextAppearance_Medium) text appearance (including font, size, style, and color)
TypefaceSpan ("monospace") text font
URLSpan ("http://orgcent.com") text hyperlink
2. flags: set some identifiers for a text segment
For example, Spannable. SPAN_EXCLUSIVE_INCLUSIVE
SPAN_COMPOSING: indicates the text information of a popular input method for temporary application: the text can be deleted or replaced.
SPAN_EXCLUSIVE_EXCLUSIVE: The included content will not expand, but will only contain the start and end points. The length cannot be 0. If all the words covered by the deleted content are also automatically deleted from the buffer zone.
Span_exclusive_wide sive: The span that can be expanded, not 0, including the end point of text insertion, rather than at their starting point. If it is 0, it is like a point.
SPAN_INCLUSIVE_EXCLUSIVE: The span that can be expanded, not 0, including the starting point of text insertion, rather than at their end point. If it is 0, it is like a point.
SPAN_INCLUSIVE_INCLUSIVE: extended span types include the start point or end point for text insertion.
SPAN_INTERMEDIATE: the flag will be set as a change in the middle span, which means there is a guarantee that there is another change. Generally, it is used to select the setting when the first offset is updated automatically.
SPAN_MARK_MARK: the span of text marking with a length of 0 and SPAN_MARK_MARK: they still insert text at the original offset.
SPAN_MARK_POINT: SPAN_MARK_POINT = SPAN_INCLUSIVE_INCLUSIVE
SPAN_PARAGRAPH: it must be the buffer of its endpoint or the start or end of the \ n character immediately after it is deleted, anchor, the endpoint is pulled to the buffer (or the end buffer) in the following \ n ). Start Point and end point with line breaks
SPAN_POINT_MARK: SPAN_POINT_MARK = SPAN_EXCLUSIVE_EXCLUSIVE.
SPAN_POINT_MARK_MASK:
SPAN_POINT_POINT: a span-type SPAN_POINT_POINT image cursor with a length of 0: When the inserted text is inserted, it is promoted in the length of its offset. Before the conceptual text insertion point
SPAN_PRIORITY: Specifies the Order Change Notification determined by the SPAN_PRIORITY Bitmap-higher numbers first. You may not need to set it. It is usually used to update data when the text changes. Before processing the data in other callback methods
SPAN_PRIORITY_SHIFT: determined sequence change notification-higher numbers first. You may not need to set it. It is usually used before other callback methods can update data when the text changes.
SPAN_USER: specifies that the SPAN_USER field is used by callers to store the scalar data related to their span objects
SPAN_USER_SHIFT: The number SPAN_USER_SHIFT, which can be used by callers to store related scalar data and their span objects.