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

Font

data class Font
kotlin.Any
   ↳ androidx.ui.text.font.Font

Defines a font to be used while rendering text.

import androidx.ui.core.Text
import androidx.ui.text.TextStyle
import androidx.ui.text.font.Font
import androidx.ui.text.font.FontFamily

val fontFamily = FontFamily(
    Font(name = "my_font_400_regular.ttf", weight = FontWeight.W400, style = FontStyle.Normal),
    Font(name = "my_font_400_italic.ttf", weight = FontWeight.W400, style = FontStyle.Italic)
)
Text(text = "Demo Text", style = TextStyle(fontFamily = fontFamily))

Summary

Nested classes

abstract

Interface used to load a font resource.

Public constructors

<init>(name: String, weight: FontWeight = FontWeight.Normal, style: FontStyle = FontStyle.Normal)

Defines a font to be used while rendering text.

Extension functions

From androidx.ui.text.font
FontFamily

Create a FontFamily from this single Font.

Inherited extension functions

From androidx.compose
operator T

IMPORTANT: This global operator is TEMPORARY, and should be removed whenever an answer for contextual composers is reached.

Properties

String

The name of the font file in font resources.

FontStyle

The style of the font, normal or italic.

FontWeight

The weight of the font.

Public constructors

<init>

Font(
    name: String,
    weight: FontWeight = FontWeight.Normal,
    style: FontStyle = FontStyle.Normal)

Defines a font to be used while rendering text.

import androidx.ui.core.Text
import androidx.ui.text.TextStyle
import androidx.ui.text.font.Font
import androidx.ui.text.font.FontFamily

val fontFamily = FontFamily(
    Font(name = "my_font_400_regular.ttf", weight = FontWeight.W400, style = FontStyle.Normal),
    Font(name = "my_font_400_italic.ttf", weight = FontWeight.W400, style = FontStyle.Italic)
)
Text(text = "Demo Text", style = TextStyle(fontFamily = fontFamily))
Parameters
name: String The name of the font file in font resources. i.e. "myfont.ttf".
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

Properties

name

val name: String

The name of the font file in font resources. i.e. "myfont.ttf".

style

val style: FontStyle

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.

weight

val weight: FontWeight

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.