The second Android 11 Developer Preview is now available, test it out and share your feedback.

androidx.ui.text.font

Classes

FileBasedFontFamily

A base class of FontFamilys that is created from file sources.

FontFamily

The base class of the font families.

FontListFontFamily

Defines a font family with list of Font.

FontWeight

The thickness of the glyphs, in a range of 1,1000.

GenericFontFamily

Defines a font family with an generic font family name.

LoadedFontFamily

Defines a font family that is already loaded Typeface.

ResourceFont

Defines a font to be used while rendering text with resource ID.

SystemFontFamily

A base class of FontFamilys installed on the system.

Enums

FontStyle

Defines whether the font is Italic or Normal.

FontSynthesis

Possible options for font synthesis.

Top-level functions summary

Font
font(resId: Int, weight: FontWeight = FontWeight.Normal, style: FontStyle = FontStyle.Normal)

Creates a Font with using resource ID.

FontListFontFamily
fontFamily(fonts: List<Font>)

Construct a font family that contains list of custom font files.

FontListFontFamily
fontFamily(vararg fonts: Font)

Construct a font family that contains list of custom font files.

LoadedFontFamily
fontFamily(typeface: Typeface)

Construct a font family that contains loaded font family: Typeface.

FontWeight
lerp(start: FontWeight, stop: FontWeight, fraction: Float)

Linearly interpolate between two font weights

Extension functions summary

For Font
FontListFontFamily

Create a FontFamily from this single font.

Top-level functions

font

fun font(
    resId: Int,
    weight: FontWeight = FontWeight.Normal,
    style: FontStyle = FontStyle.Normal
): Font

Creates a Font with using resource ID.

Parameters
resId: Int The resource ID of the font file in font resources. i.e. "R.font.myfont".
weight: FontWeight = FontWeight.Normal The weight of the font. The system uses this to match a font to a font request that is given in a androidx.ui.text.SpanStyle.
style: FontStyle = FontStyle.Normal The style of the font, normal or italic. The system uses this to match a font to a font request that is given in a androidx.ui.text.SpanStyle.

See Also

fontFamily

fun fontFamily(fonts: List<Font>): FontListFontFamily

Construct a font family that contains list of custom font files.

Parameters
fonts: List<Font> list of font files

fontFamily

fun fontFamily(vararg fonts: Font): FontListFontFamily

Construct a font family that contains list of custom font files.

Parameters
vararg fonts: Font list of font files

fontFamily

fun fontFamily(typeface: Typeface): LoadedFontFamily

Construct a font family that contains loaded font family: Typeface.

Parameters
typeface: Typeface A typeface instance.

lerp

fun lerp(
    start: FontWeight,
    stop: FontWeight,
    fraction: Float
): FontWeight

Linearly interpolate between two font weights

Rather than using fractional weights, the interpolation rounds to the nearest weight.

The fraction argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning start (or something equivalent to start), 1.0 meaning that the interpolation has finished, returning stop (or something equivalent to stop), and values in between meaning that the interpolation is at the relevant point on the timeline between start and stop. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid (and can easily be generated by curves).

Values for fraction are usually obtained from an Animation, such as an AnimationController.

Extension functions

asFontFamily

fun Font.asFontFamily(): FontListFontFamily

Create a FontFamily from this single font.