AndroidFont


Font for use on Android.

All AndroidFont produce an android.graphics.Typeface which may be used to draw text on Android. This is the main low-level API for introducing a new Font description to Compose on Android for both blocking and async load.

You may subclass this to add new types of font descriptions that may be used in FontListFontFamily. For example, you can add a FontLoadingStrategy.Blocking font that returns a Typeface from a local resource not supported by an existing Font. Or, you can create an FontLoadingStrategy.Async font that loads a font file from your server.

When introducing new font descriptors, it is recommended to follow the patterns of providing a public Font constructor and a private implementation class:

  1. Declare an internal or private subclass of AndroidFont

  2. Expose a public Font(...) constructor that returns your new type.

Font constructors are

  1. Regular functions named Font that return type Font

  2. The first argument is the font name, or similar object that describes the font uniquely

  3. If the font has a provider, loader, or similar argument, put it after the font name.

  4. The last two arguments are FontWeight and FontStyle.

Examples of Font constructors:

fun Font("myIdentifier", MyFontLoader, FontWeight, FontStyle): Font
fun
Font(CustomFontDescription(...), MyFontLoader, FontWeight, FontStyle): Font
fun
Font(CustomFontDescription(...), FontWeight, FontStyle): Font

Summary

Nested types

Loader for loading an AndroidFont and producing an android.graphics.Typeface.

Public constructors

AndroidFont(
    loadingStrategy: FontLoadingStrategy,
    typefaceLoader: AndroidFont.TypefaceLoader
)

This function is deprecated. Replaced with fontVariation constructor

android
AndroidFont(
    loadingStrategy: FontLoadingStrategy,
    typefaceLoader: AndroidFont.TypefaceLoader,
    variationSettings: FontVariation.Settings
)
android

Public properties

final FontLoadingStrategy

loadingStrategy this font will provide in fallback chains

android
AndroidFont.TypefaceLoader

a loader that knows how to load this AndroidFont, may be shared between several fonts

android
FontVariation.Settings

The settings that will be applied to this font, if supported by the font.

android

Inherited properties

From androidx.compose.ui.text.font.Font
abstract FontStyle

The style of the font, normal or italic.

android
abstract FontWeight

The weight of the font.

android

Public constructors

AndroidFont

AndroidFont(
    loadingStrategy: FontLoadingStrategy,
    typefaceLoader: AndroidFont.TypefaceLoader
)

AndroidFont

AndroidFont(
    loadingStrategy: FontLoadingStrategy,
    typefaceLoader: AndroidFont.TypefaceLoader,
    variationSettings: FontVariation.Settings
)
Parameters
loadingStrategy: FontLoadingStrategy

loadingStrategy this font will provide in fallback chains

typefaceLoader: AndroidFont.TypefaceLoader

a loader that knows how to load this AndroidFont, may be shared between several fonts

Public properties

loadingStrategy

final val loadingStrategyFontLoadingStrategy

loadingStrategy this font will provide in fallback chains

typefaceLoader

val typefaceLoaderAndroidFont.TypefaceLoader

a loader that knows how to load this AndroidFont, may be shared between several fonts

variationSettings

val variationSettingsFontVariation.Settings

The settings that will be applied to this font, if supported by the font.

If the font does not support a FontVariation.Setting, it has no effect.

Subclasses are required to apply these variation settings during font loading path on appropriate API levels, for example by using Typeface.Builder.setFontVariationSettings.

Subclasses may safely apply all variation settings without querying the font file. Android will ignore any unsupported axis.