{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

ResourceFont

public final class ResourceFont implements Font


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
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight

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)
See also
FontFamily

Summary

Public methods

final @NonNull ResourceFont
copy(int resId, @NonNull FontWeight weight, @NonNull FontStyle style)
final @NonNull ResourceFont
@ExperimentalTextApi
copy(
    int resId,
    @NonNull FontWeight weight,
    @NonNull FontStyle style,
    @NonNull FontLoadingStrategy loadingStrategy,
    @NonNull FontVariation.Settings variationSettings
)
boolean
equals(Object other)
@NonNull FontLoadingStrategy

Loading strategy for this font.

final int

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

@NonNull FontStyle

The style of the font, normal or italic.

final @NonNull FontVariation.Settings
@NonNull FontWeight

The weight of the font.

int
@NonNull String

Public methods

copy

public final @NonNull ResourceFont copy(int resId, @NonNull FontWeight weight, @NonNull FontStyle style)

copy

@ExperimentalTextApi
public final @NonNull ResourceFont copy(
    int resId,
    @NonNull FontWeight weight,
    @NonNull FontStyle style,
    @NonNull FontLoadingStrategy loadingStrategy,
    @NonNull FontVariation.Settings variationSettings
)

equals

public boolean equals(Object other)

getLoadingStrategy

@ExperimentalTextApi
public @NonNull FontLoadingStrategy getLoadingStrategy()

Loading strategy for this font.

getResId

public final int getResId()

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

getStyle

public @NonNull FontStyle getStyle()

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.

getVariationSettings

@ExperimentalTextApi
public final @NonNull FontVariation.Settings getVariationSettings()

getWeight

public @NonNull FontWeight getWeight()

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.

hashCode

public int hashCode()

toString

public @NonNull String toString()