Android 12 Developer Preview is here! Try it out, and give us your feedback!

ResourceFont

class ResourceFont : Font
kotlin.Any
   ↳ androidx.compose.ui.text.font.ResourceFont

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

import androidx.compose.material.Text
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily

val fontFamily = FontFamily(
    Font(
        resId = R.font.my_font_400_regular,
        weight = FontWeight.W400,
        style = FontStyle.Normal
    ),
    Font(
        resId = R.font.my_font_400_italic,
        weight = FontWeight.W400,
        style = FontStyle.Italic
    )
)
Text(text = "Demo Text", fontFamily = fontFamily)

Summary

Public methods
ResourceFont
copy(resId: Int = this.resId, weight: FontWeight = this.weight, style: FontStyle = this.style)

Boolean
equals(other: Any?)

Int

String

Inherited extension functions
From androidx.compose.ui.text.font
FontFamily

Create a FontFamily from this single font.

Properties
Int

The resource ID of the font file in font resources.

FontStyle

The style of the font, normal or italic.

FontWeight

The weight of the font.

Public methods

copy

fun copy(
    resId: Int = this.resId,
    weight: FontWeight = this.weight,
    style: FontStyle = this.style
): ResourceFont

equals

fun equals(other: Any?): Boolean

hashCode

fun hashCode(): Int

toString

fun toString(): String

Properties

resId

val resId: Int

The resource ID of the font file in font resources. i.e. "R.font.myfont".

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.compose.ui.text.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 androidx.compose.ui.text.TextStyle.