FontFamily

@Immutable data class FontFamily : List<Font>
kotlin.Any
   ↳ androidx.ui.text.font.FontFamily

Defines a font family. It can be constructed via a generic font family such as serif, sans-serif (i.e. FontFamily("sans-serif"). It can also be constructed by a set of custom fonts.

import androidx.ui.core.Text
import androidx.ui.text.TextStyle

Text(
    text = "Demo Text sans-serif",
    style = TextStyle(fontFamily = FontFamily.SansSerif)
)
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

Public constructors

<init>(genericFamily: String)

Constructs a generic font family.

<init>(font: Font)

Construct a font family that contains a single custom font file.

<init>(fonts: List<Font>)

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

<init>(vararg fonts: Font)

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

Properties

List<Font>

String?

Companion properties

FontFamily

Cursive, hand-written like font family.

FontFamily

Font family where glyphs have the same fixed width.

FontFamily

Font family with low contrast and plain stroke endings.

FontFamily

The formal text style for scripts.

Public constructors

<init>

FontFamily(genericFamily: String)

Constructs a generic font family.

Parameters
genericFamily: String the generic font family name to be used. i.e. "sans-serif".

<init>

FontFamily(font: Font)

Construct a font family that contains a single custom font file.

Parameters
font: Font font file

<init>

FontFamily(fonts: List<Font>)

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

Parameters
fonts: List<Font> list of font files

<init>

FontFamily(vararg fonts: Font)

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

Parameters
vararg fonts: Font list of font files

Properties

fonts

val fonts: List<Font>

genericFamily

val genericFamily: String?

Companion properties

Cursive

val Cursive: FontFamily

Cursive, hand-written like font family.

If the device doesn't support this font family, the system will fallback to the default font.

import androidx.ui.core.Text
import androidx.ui.text.TextStyle

Text(
    text = "Demo Text cursive",
    style = TextStyle(fontFamily = FontFamily.Cursive)
)

Monospace

val Monospace: FontFamily

Font family where glyphs have the same fixed width.

import androidx.ui.core.Text
import androidx.ui.text.TextStyle

Text(
    text = "Demo Text monospace",
    style = TextStyle(fontFamily = FontFamily.Monospace)
)

SansSerif

val SansSerif: FontFamily

Font family with low contrast and plain stroke endings.

import androidx.ui.core.Text
import androidx.ui.text.TextStyle

Text(
    text = "Demo Text sans-serif",
    style = TextStyle(fontFamily = FontFamily.SansSerif)
)

Serif

val Serif: FontFamily

The formal text style for scripts.

import androidx.ui.core.Text
import androidx.ui.text.TextStyle

Text(
    text = "Demo Text serif",
    style = TextStyle(fontFamily = FontFamily.Serif)
)