SpannableString for Android development and android Development

Source: Internet
Author: User

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!

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.