TextAppearanceSpan


public class TextAppearanceSpan
extends MetricAffectingSpan implements ParcelableSpan

java.lang.Object
   ↳ android.text.style.CharacterStyle
     ↳ android.text.style.MetricAffectingSpan
       ↳ android.text.style.TextAppearanceSpan


Sets the text appearance using the given TextAppearance attributes. By default TextAppearanceSpan only changes the specified attributes in XML. textColorHighlight, textColorHint, textAllCaps and fallbackLineSpacing are not supported by TextAppearanceSpan.

Summary

XML attributes

android:elegantTextHeight Elegant text height, especially for less compacted complex script text. 
android:fontFamily Font family (named by string or as a font resource reference) for the text. 
android:fontFeatureSettings Font feature settings. 
android:fontVariationSettings Font variation settings. 
android:letterSpacing Text letter-spacing. 
android:shadowColor Place a blurred shadow of text underneath the text, drawn with the specified color. 
android:shadowDx Horizontal offset of the text shadow. 
android:shadowDy Vertical offset of the text shadow. 
android:shadowRadius Blur radius of the text shadow. 
android:textColor Text color. 
android:textColorLink Color of the links. 
android:textFontWeight Weight for the font used in the TextView. 
android:textSize Size of the text. 
android:textStyle Style (normal, bold, italic, bold|italic) for the text. 
android:typeface Typeface (normal, sans, serif, monospace) for the text. 

Inherited constants

Public constructors

TextAppearanceSpan(Context context, int appearance)

Uses the specified TextAppearance resource to determine the text appearance.

TextAppearanceSpan(Context context, int appearance, int colorList)

Uses the specified TextAppearance resource to determine the text appearance, and the specified text color resource to determine the color.

TextAppearanceSpan(Parcel src)
TextAppearanceSpan(String family, int style, int size, ColorStateList color, ColorStateList linkColor)

Makes text be drawn with the specified typeface, size, style, and colors.

Public methods

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

String getFamily()

Returns the typeface family specified by this span, or null if it does not specify one.

String getFontFeatureSettings()

Returns the font feature settings specified by this span, or null if it does not specify one.

String getFontVariationSettings()

Returns the font variation settings specified by this span, or null if it does not specify one.

float getLetterSpacing()

Returns the value of letter spacing to be added in em unit.

ColorStateList getLinkTextColor()

Returns the link color specified by this span, or null if it does not specify one.

int getShadowColor()

Returns the color of the text shadow specified by this span, or 0 if it does not specify one.

float getShadowDx()

Returns the horizontal offset of the text shadow specified by this span, or 0.0f if it does not specify one.

float getShadowDy()

Returns the vertical offset of the text shadow specified by this span, or 0.0f if it does not specify one.

float getShadowRadius()

Returns the blur radius of the text shadow specified by this span, or 0.0f if it does not specify one.

int getSpanTypeId()

Return a special type identifier for this span class.

ColorStateList getTextColor()

Returns the text color specified by this span, or null if it does not specify one.

int getTextFontWeight()

Returns the text font weight specified by this span, or FontStyle.FONT_WEIGHT_UNSPECIFIED if it does not specify one.

LocaleList getTextLocales()

Returns the LocaleList specified by this span, or null if it does not specify one.

int getTextSize()

Returns the text size specified by this span, or -1 if it does not specify one.

int getTextStyle()

Returns the text style specified by this span, or 0 if it does not specify one.

Typeface getTypeface()

Returns the typeface specified by this span, or null if it does not specify one.

boolean isElegantTextHeight()

Returns the value of elegant height metrics flag specified by this span, or false if it does not specify one.

String toString()

Returns a string representation of the object.

void updateDrawState(TextPaint ds)
void updateMeasureState(TextPaint ds)

Classes that extend MetricAffectingSpan implement this method to update the text formatting in a way that can change the width or height of characters.

void writeToParcel(Parcel dest, int flags)

Flatten this object in to a Parcel.

Inherited methods

XML attributes

android:elegantTextHeight

Elegant text height, especially for less compacted complex script text.

May be a boolean value, such as "true" or "false".

android:fontFamily

Font family (named by string or as a font resource reference) for the text.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:fontFeatureSettings

Font feature settings.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:fontVariationSettings

Font variation settings.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:letterSpacing

Text letter-spacing.

May be a floating point value, such as "1.2".

android:shadowColor

Place a blurred shadow of text underneath the text, drawn with the specified color. The text shadow produced does not interact with properties on View that are responsible for real time shadows, elevation and translationZ.

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

android:shadowDx

Horizontal offset of the text shadow.

May be a floating point value, such as "1.2".

android:shadowDy

Vertical offset of the text shadow.

May be a floating point value, such as "1.2".

android:shadowRadius

Blur radius of the text shadow.

May be a floating point value, such as "1.2".

android:textColor

Text color.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

Color of the links.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

android:textFontWeight

Weight for the font used in the TextView.

May be an integer value, such as "100".

android:textSize

Size of the text. Recommended dimension type for text is "sp" for scaled-pixels (example: 15sp).

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:textStyle

Style (normal, bold, italic, bold|italic) for the text.

Must be one or more (separated by '|') of the following constant values.

ConstantValueDescription
bold1
italic2
normal0

android:typeface

Typeface (normal, sans, serif, monospace) for the text.

Must be one of the following constant values.

ConstantValueDescription
monospace3
normal0
sans1
serif2

Public constructors

TextAppearanceSpan

Added in API level 1
public TextAppearanceSpan (Context context, 
                int appearance)

Uses the specified TextAppearance resource to determine the text appearance. The appearance should be, for example, android.R.style.TextAppearance_Small.

Parameters
context Context

appearance int

TextAppearanceSpan

Added in API level 1
public TextAppearanceSpan (Context context, 
                int appearance, 
                int colorList)

Uses the specified TextAppearance resource to determine the text appearance, and the specified text color resource to determine the color. The appearance should be, for example, android.R.style.TextAppearance_Small, and the colorList should be, for example, android.R.styleable.Theme_textColorPrimary.

Parameters
context Context

appearance int

colorList int

TextAppearanceSpan

Added in API level 3
public TextAppearanceSpan (Parcel src)

Parameters
src Parcel

TextAppearanceSpan

Added in API level 1
public TextAppearanceSpan (String family, 
                int style, 
                int size, 
                ColorStateList color, 
                ColorStateList linkColor)

Makes text be drawn with the specified typeface, size, style, and colors.

Parameters
family String

style int

size int

color ColorStateList

linkColor ColorStateList

Public methods

describeContents

Added in API level 3
public int describeContents ()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(android.os.Parcel, int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or CONTENTS_FILE_DESCRIPTOR

getFamily

Added in API level 1
public String getFamily ()

Returns the typeface family specified by this span, or null if it does not specify one.

Returns
String

getFontFeatureSettings

Added in API level 29
public String getFontFeatureSettings ()

Returns the font feature settings specified by this span, or null if it does not specify one.

Returns
String

getFontVariationSettings

Added in API level 29
public String getFontVariationSettings ()

Returns the font variation settings specified by this span, or null if it does not specify one.

Returns
String

getLetterSpacing

Added in API level 34
public float getLetterSpacing ()

Returns the value of letter spacing to be added in em unit.

Returns
float a letter spacing amount

getLinkTextColor

Added in API level 1
public ColorStateList getLinkTextColor ()

Returns the link color specified by this span, or null if it does not specify one.

Returns
ColorStateList

getShadowColor

Added in API level 29
public int getShadowColor ()

Returns the color of the text shadow specified by this span, or 0 if it does not specify one.

Returns
int

getShadowDx

Added in API level 29
public float getShadowDx ()

Returns the horizontal offset of the text shadow specified by this span, or 0.0f if it does not specify one.

Returns
float

getShadowDy

Added in API level 29
public float getShadowDy ()

Returns the vertical offset of the text shadow specified by this span, or 0.0f if it does not specify one.

Returns
float

getShadowRadius

Added in API level 29
public float getShadowRadius ()

Returns the blur radius of the text shadow specified by this span, or 0.0f if it does not specify one.

Returns
float

getSpanTypeId

Added in API level 3
public int getSpanTypeId ()

Return a special type identifier for this span class.

Returns
int

getTextColor

Added in API level 1
public ColorStateList getTextColor ()

Returns the text color specified by this span, or null if it does not specify one.

Returns
ColorStateList

getTextFontWeight

Added in API level 29
public int getTextFontWeight ()

Returns the text font weight specified by this span, or FontStyle.FONT_WEIGHT_UNSPECIFIED if it does not specify one.

Returns
int

getTextLocales

Added in API level 29
public LocaleList getTextLocales ()

Returns the LocaleList specified by this span, or null if it does not specify one.

Returns
LocaleList

getTextSize

Added in API level 1
public int getTextSize ()

Returns the text size specified by this span, or -1 if it does not specify one.

Returns
int

getTextStyle

Added in API level 1
public int getTextStyle ()

Returns the text style specified by this span, or 0 if it does not specify one.

Returns
int

getTypeface

Added in API level 29
public Typeface getTypeface ()

Returns the typeface specified by this span, or null if it does not specify one.

Returns
Typeface

isElegantTextHeight

Added in API level 29
public boolean isElegantTextHeight ()

Returns the value of elegant height metrics flag specified by this span, or false if it does not specify one.

Returns
boolean

toString

Added in API level 1
public String toString ()

Returns a string representation of the object.

Returns
String a string representation of the object.

updateDrawState

Added in API level 1
public void updateDrawState (TextPaint ds)

Parameters
ds TextPaint

updateMeasureState

Added in API level 1
public void updateMeasureState (TextPaint ds)

Classes that extend MetricAffectingSpan implement this method to update the text formatting in a way that can change the width or height of characters.

Parameters
ds TextPaint: the paint used for drawing the text This value cannot be null.

writeToParcel

Added in API level 3
public void writeToParcel (Parcel dest, 
                int flags)

Flatten this object in to a Parcel.

Parameters
dest Parcel: The Parcel in which the object should be written. This value cannot be null.

flags int: Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES