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

AndroidFontKt

public final class AndroidFontKt


Summary

Public methods

static final @NonNull Font
@RequiresApi(value = 26)
Font(
    @NonNull ParcelFileDescriptor fileDescriptor,
    @NonNull FontWeight weight,
    @NonNull FontStyle style,
    @NonNull FontVariation.Settings variationSettings
)

Create a Font declaration from a ParcelFileDescriptor.

static final @NonNull Font
Font(
    @NonNull File file,
    @NonNull FontWeight weight,
    @NonNull FontStyle style,
    @NonNull FontVariation.Settings variationSettings
)

Create a Font declaration from a file.

static final @NonNull Font
Font(
    @NonNull String path,
    @NonNull AssetManager assetManager,
    @NonNull FontWeight weight,
    @NonNull FontStyle style,
    @NonNull FontVariation.Settings variationSettings
)

Create a Font declaration from a file in the assets directory.

Public methods

Font

@RequiresApi(value = 26)
public static final @NonNull Font Font(
    @NonNull ParcelFileDescriptor fileDescriptor,
    @NonNull FontWeight weight,
    @NonNull FontStyle style,
    @NonNull FontVariation.Settings variationSettings
)

Create a Font declaration from a ParcelFileDescriptor. The content of the ParcelFileDescriptor is read during construction.

Parameters
@NonNull ParcelFileDescriptor fileDescriptor

the file descriptor for the font file.

@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 FontVariation.Settings variationSettings

these settings are applied to a variable font when the font is loaded

Font

public static final @NonNull Font Font(
    @NonNull File file,
    @NonNull FontWeight weight,
    @NonNull FontStyle style,
    @NonNull FontVariation.Settings variationSettings
)

Create a Font declaration from a file. The content of the File is read during construction.

Parameters
@NonNull File file

the font file.

@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 FontVariation.Settings variationSettings

on API 26 and above these settings are applied to a variable font when the font is loaded

Font

public static final @NonNull Font Font(
    @NonNull String path,
    @NonNull AssetManager assetManager,
    @NonNull FontWeight weight,
    @NonNull FontStyle style,
    @NonNull FontVariation.Settings variationSettings
)

Create a Font declaration from a file in the assets directory. The content of the File is read during construction.

Parameters
@NonNull String path

full path starting from the assets directory (i.e. dir/myfont.ttf for assets/dir/myfont.ttf).

@NonNull AssetManager assetManager

Android AssetManager

@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 FontVariation.Settings variationSettings

on API 26 and above these settings are applied to a variable font when the font is loaded