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.

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 TextStyle.
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 TextStyle.

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 TextStyle.

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 TextStyle.