TypefaceSpan
open class TypefaceSpan : MetricAffectingSpan, ParcelableSpan
kotlin.Any | |||
↳ | android.text.style.CharacterStyle | ||
↳ | android.text.style.MetricAffectingSpan | ||
↳ | android.text.style.TypefaceSpan |
Span that updates the typeface of the text it's attached to. The TypefaceSpan
can be constructed either based on a font family or based on a Typeface
. When TypefaceSpan(java.lang.String)
is used, the previous style of the TextView
is kept. When TypefaceSpan(android.graphics.Typeface)
is used, the Typeface
style replaces the TextView
's style.
For example, let's consider a TextView
with android:textStyle="italic"
and a typeface created based on a font from resources, with a bold style. When applying a TypefaceSpan
based the typeface, the text will only keep the bold style, overriding the TextView
's textStyle. When applying a TypefaceSpan
based on a font family: "monospace", the resulted text will keep the italic style.
Typeface myTypeface = Typeface.create(ResourcesCompat.getFont(context, R.font.acme), Typeface.BOLD); SpannableString string = new SpannableString("Text with typeface span."); string.setSpan(new TypefaceSpan(myTypeface), 10, 18, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); string.setSpan(new TypefaceSpan("monospace"), 19, 22, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TypefaceSpan
s constructed based on a font from resource and from a font family.
Summary
Public constructors | |
---|---|
TypefaceSpan(typeface: Typeface) Constructs a |
|
TypefaceSpan(src: Parcel) Constructs a |
|
TypefaceSpan(family: String?) Constructs a |
Public methods | |
---|---|
open Int | |
open String? |
Returns the font family name set in the span. |
open Int | |
open Typeface? |
Returns the typeface set in the span. |
open String |
toString() |
open Unit |
updateDrawState(ds: TextPaint) |
open Unit |
updateMeasureState(paint: TextPaint) Classes that extend MetricAffectingSpan implement this method to update the text formatting in a way that can change the width or height of characters. |
open Unit |
writeToParcel(dest: Parcel, flags: Int) Flatten this object in to a Parcel. |
Inherited functions | |
---|---|
Public constructors
TypefaceSpan
TypefaceSpan(typeface: Typeface)
Constructs a TypefaceSpan
from a Typeface
. The previous style of the TextPaint is overridden and the style of the typeface is used.
Parameters | |
---|---|
typeface |
Typeface: the typeface This value cannot be null . |
TypefaceSpan
TypefaceSpan(src: Parcel)
Constructs a TypefaceSpan
from a parcel.
Parameters | |
---|---|
src |
Parcel: This value cannot be null . |
TypefaceSpan
TypefaceSpan(family: String?)
Constructs a TypefaceSpan
based on the font family. The previous style of the TextPaint is kept. If the font family is null, the text paint is not modified.
Parameters | |
---|---|
family |
String?: The font family for this typeface. Examples include "monospace", "serif", and "sans-serif" This value may be null . |
Public methods
describeContents
open fun describeContents(): Int
Return | |
---|---|
Int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR |
getFamily
open fun getFamily(): String?
Returns the font family name set in the span.
Return | |
---|---|
String? |
the font family name This value may be null . |
See Also
getTypeface
open fun getTypeface(): Typeface?
Returns the typeface set in the span.
Return | |
---|---|
Typeface? |
the typeface set This value may be null . |
See Also
toString
open fun toString(): String
Return | |
---|---|
String |
a string representation of the object. |
updateDrawState
open fun updateDrawState(ds: TextPaint): Unit
Parameters | |
---|---|
ds |
TextPaint: This value cannot be null . |
updateMeasureState
open fun updateMeasureState(paint: TextPaint): Unit
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 | |
---|---|
textPaint |
the paint used for drawing the text This value cannot be null . |
paint |
TextPaint: This value cannot be null . |
writeToParcel
open fun writeToParcel(
dest: Parcel,
flags: Int
): Unit
Flatten this object in to a Parcel.
Parameters | |
---|---|
dest |
Parcel: This value cannot be null . |
flags |
Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE . Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE , and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES |