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

FontKt

public final class FontKt


Summary

Public methods

static final @NonNull Font
Font(
    int resId,
    @NonNull FontWeight weight,
    @NonNull FontStyle style,
    @NonNull FontLoadingStrategy loadingStrategy
)

Creates a Font with using resource ID.

static final @NonNull Font
@ExperimentalTextApi
Font(
    int resId,
    @NonNull FontWeight weight,
    @NonNull FontStyle style,
    @NonNull FontLoadingStrategy loadingStrategy,
    @NonNull FontVariation.Settings variationSettings
)
static final @NonNull FontFamily

Create a FontFamily from this single Font.

Public methods

Font

public static final @NonNull Font Font(
    int resId,
    @NonNull FontWeight weight,
    @NonNull FontStyle style,
    @NonNull FontLoadingStrategy loadingStrategy
)

Creates a Font with using resource ID.

Allows control over FontLoadingStrategy strategy. You may supply FontLoadingStrategy.Blocking, or FontLoadingStrategy.OptionalLocal for fonts that are expected on the first frame.

FontLoadingStrategy.Async, will load the font in the background and cause text reflow when loading completes. Fonts loaded from a remote source via resources should use FontLoadingStrategy.Async.

Parameters
int resId

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

@NonNull FontWeight weight

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

@NonNull FontStyle style

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

@NonNull FontLoadingStrategy loadingStrategy

Load strategy for this font, may be async for async resource fonts

See also
FontFamily

Font

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

toFontFamily

public static final @NonNull FontFamily toFontFamily(@NonNull Font receiver)

Create a FontFamily from this single Font.