Google is committed to advancing racial equity for Black communities. See how.

ResourceFont

data 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.foundation.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 constructors
<init>(resId: Int, weight: FontWeight = FontWeight.Normal, style: FontStyle = FontStyle.Normal)

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

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

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 constructors

<init>

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

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

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

See Also

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.