# AndroidFont

Artifact: [androidx.compose.ui:ui-text](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/text/font/AndroidFont.android.kt+class:androidx.compose.ui.text.font.AndroidFont) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0) Common/AllAndroid/JVM
- android

  ```
  abstract class AndroidFont : Font
  ```

*** ** * ** ***

Font for use on Android.

All `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont` produce an `https://developer.android.com/reference/android/graphics/Typeface.html` 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 `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontListFontFamily`. For example, you can add a `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontLoadingStrategy#Blocking()` font that returns a Typeface from a local resource not supported by an existing `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/Font`. Or, you can create an `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/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:

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

## Summary

| ### Nested types |
|---|
| `interface https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont.TypefaceLoader` Loader for loading an `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont` and producing an `https://developer.android.com/reference/android/graphics/Typeface.html`. |

| ### Public constructors |
|---|---|
| `[AndroidFont](https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont#AndroidFont(androidx.compose.ui.text.font.FontLoadingStrategy,androidx.compose.ui.text.font.AndroidFont.TypefaceLoader))( loadingStrategy: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontLoadingStrategy, typefaceLoader: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont.TypefaceLoader )` **This function is deprecated.** Replaced with fontVariation constructor | android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont#AndroidFont(androidx.compose.ui.text.font.FontLoadingStrategy,androidx.compose.ui.text.font.AndroidFont.TypefaceLoader,androidx.compose.ui.text.font.FontVariation.Settings)( loadingStrategy: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontLoadingStrategy, typefaceLoader: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont.TypefaceLoader, variationSettings: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontVariation.Settings )` | android |

| ### Public properties |
|---|---|---|
| `final https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontLoadingStrategy` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont#loadingStrategy()` loadingStrategy this font will provide in fallback chains | android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont.TypefaceLoader` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont#typefaceLoader()` a loader that knows how to load this `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont`, may be shared between several fonts | android |
| `final https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontVariation.Settings` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont#variationSettings()` The settings that will be applied to this font, if supported by the font. | android |

### Inherited properties

From [androidx.compose.ui.text.font.Font](https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/Font) `abstract https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle` `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/Font#style()`

The style of the font, normal or italic.
android `abstract https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight` `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/Font#weight()`

The weight of the font.
android

## Public constructors

### AndroidFont

android Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.9.0) Deprecated in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.9.0)

```
[AndroidFont](https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont#AndroidFont(androidx.compose.ui.text.font.FontLoadingStrategy,androidx.compose.ui.text.font.AndroidFont.TypefaceLoader))(
    loadingStrategy: FontLoadingStrategy,
    typefaceLoader: AndroidFont.TypefaceLoader
)
```

> [!CAUTION]
> **This function is deprecated.**   
> Replaced with fontVariation constructor, use this instead:
>
> ```kotlin
> AndroidFont(loadingStrategy, typefaceLoader, FontVariation.Settings())
> ```

### AndroidFont

android Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.9.0)

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

| Parameters |
|---|---|
| `loadingStrategy: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontLoadingStrategy` | loadingStrategy this font will provide in fallback chains |
| `typefaceLoader: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont.TypefaceLoader` | a loader that knows how to load this `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont`, may be shared between several fonts |
| `variationSettings: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontVariation.Settings` | the settings that will be applied to this font, if supported by the font |

## Public properties

### loadingStrategy

android

```
final val loadingStrategy: FontLoadingStrategy
```

loadingStrategy this font will provide in fallback chains

### typefaceLoader

android Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val typefaceLoader: AndroidFont.TypefaceLoader
```

a loader that knows how to load this `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/AndroidFont`, may be shared between several fonts

### variationSettings

android Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.3.0)

```
final val variationSettings: FontVariation.Settings
```

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

If the font does not support a `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/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 `https://developer.android.com/reference/android/graphics/Typeface.Builder.html#setFontVariationSettings(android.graphics.fonts.FontVariationAxis[])`.

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