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
.
See also:
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(String family, int style, int size, ColorStateList color, ColorStateList linkColor)
Makes text be drawn with the specified typeface, size, style, and colors. |
|
TextAppearanceSpan(Parcel src)
|
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 |
String
|
getFontFeatureSettings()
Returns the font feature settings specified by this span, or |
String
|
getFontVariationSettings()
Returns the font variation settings specified by this span, or |
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 |
int
|
getShadowColor()
Returns the color of the text shadow specified by this span, or |
float
|
getShadowDx()
Returns the horizontal offset of the text shadow specified by this span, or |
float
|
getShadowDy()
Returns the vertical offset of the text shadow specified by this span, or |
float
|
getShadowRadius()
Returns the blur radius of the text shadow specified by this span, or |
int
|
getSpanTypeId()
Return a special type identifier for this span class. |
ColorStateList
|
getTextColor()
Returns the text color specified by this span, or |
int
|
getTextFontWeight()
Returns the text font weight specified by this span, or
|
LocaleList
|
getTextLocales()
Returns the |
int
|
getTextSize()
Returns the text size specified by this span, or |
int
|
getTextStyle()
Returns the text style specified by this span, or |
Typeface
|
getTypeface()
Returns the typeface specified by this span, or |
boolean
|
isElegantTextHeight()
Returns the value of elegant height metrics flag specified by this span,
or |
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
".
android:textColorLink
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.
Constant | Value | Description |
---|---|---|
bold | 1 | |
italic | 2 | |
normal | 0 |
android:typeface
Typeface (normal, sans, serif, monospace) for the text.
Must be one of the following constant values.
Constant | Value | Description |
---|---|---|
monospace | 3 | |
normal | 0 | |
sans | 1 | |
serif | 2 |
Public constructors
TextAppearanceSpan
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
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
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 |
TextAppearanceSpan
public TextAppearanceSpan (Parcel src)
Parameters | |
---|---|
src |
Parcel |
Public methods
describeContents
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
public String getFamily ()
Returns the typeface family specified by this span, or null
if it does not specify one.
Returns | |
---|---|
String |
getFontFeatureSettings
public String getFontFeatureSettings ()
Returns the font feature settings specified by this span, or null
if it does not specify one.
Returns | |
---|---|
String |
getFontVariationSettings
public String getFontVariationSettings ()
Returns the font variation settings specified by this span, or null
if it does not specify one.
Returns | |
---|---|
String |
getLetterSpacing
public float getLetterSpacing ()
Returns the value of letter spacing to be added in em unit.
Returns | |
---|---|
float |
a letter spacing amount |
getLinkTextColor
public ColorStateList getLinkTextColor ()
Returns the link color specified by this span, or null
if it does not specify one.
Returns | |
---|---|
ColorStateList |
getShadowColor
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
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
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
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
public int getSpanTypeId ()
Return a special type identifier for this span class.
Returns | |
---|---|
int |
getTextColor
public ColorStateList getTextColor ()
Returns the text color specified by this span, or null
if it does not specify one.
Returns | |
---|---|
ColorStateList |
getTextFontWeight
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
public LocaleList getTextLocales ()
Returns the LocaleList
specified by this span, or null
if it does not specify one.
Returns | |
---|---|
LocaleList |
getTextSize
public int getTextSize ()
Returns the text size specified by this span, or -1
if it does not specify one.
Returns | |
---|---|
int |
getTextStyle
public int getTextStyle ()
Returns the text style specified by this span, or 0
if it does not specify one.
Returns | |
---|---|
int |
getTypeface
public Typeface getTypeface ()
Returns the typeface specified by this span, or null
if it does not specify one.
Returns | |
---|---|
Typeface |
isElegantTextHeight
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
public String toString ()
Returns a string representation of the object.
Returns | |
---|---|
String |
a string representation of the object. |
updateDrawState
public void updateDrawState (TextPaint ds)
Parameters | |
---|---|
ds |
TextPaint |
updateMeasureState
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
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 |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.