# Font.Builder

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/graphics/fonts/Font.Builder "View this page in Java")  

```
class Builder
```

|---|----------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                             ||
| ↳ | [android.graphics.fonts.Font.Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#) |

A builder class for creating new Font.

## Summary

|                                                                                                                                                                                                                                                      Public constructors                                                                                                                                                                                                                                                       ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#Builder(android.content.res.AssetManager,%20kotlin.String))`(`am:` `[AssetManager](https://developer.android.com/reference/kotlin/android/content/res/AssetManager.html#)`, `path:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`)` Constructs a builder from an asset manager and a file path in an asset directory.                                                                     |
| [Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#Builder(android.content.res.Resources,%20kotlin.Int))`(`res:` `[Resources](https://developer.android.com/reference/kotlin/android/content/res/Resources.html#)`, `resId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Constructs a builder from resources.                                                                                                                                  |
| [Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#Builder(android.graphics.fonts.Font))`(`font:` `[Font](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font)`)` Constructs a builder from existing Font instance.                                                                                                                                                                                                                                        |
| [Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#Builder(android.os.ParcelFileDescriptor))`(`fd:` `[ParcelFileDescriptor](https://developer.android.com/reference/kotlin/android/os/ParcelFileDescriptor.html#)`)` Constructs a builder with a file descriptor.                                                                                                                                                                                                                 |
| [Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#Builder(android.os.ParcelFileDescriptor,%20kotlin.Long,%20kotlin.Long))`(`fd:` `[ParcelFileDescriptor](https://developer.android.com/reference/kotlin/android/os/ParcelFileDescriptor.html#)`, `offset:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`, `size:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Constructs a builder with a file descriptor. |
| [Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#Builder(java.io.File))`(`path:` `[File](https://developer.android.com/reference/kotlin/java/io/File.html#)`)` Constructs a builder with a file path.                                                                                                                                                                                                                                                                           |
| [Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#Builder(java.nio.ByteBuffer))`(`buffer:` `[ByteBuffer](https://developer.android.com/reference/kotlin/java/nio/ByteBuffer.html#)`)` Constructs a builder with a byte buffer.                                                                                                                                                                                                                                                   |

|                                                                                                                                                                                                                                              Public methods                                                                                                                                                                                                                                              ||
|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Font](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font)                  | [build](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#build())`()` Creates the font based on the configured values.                                                                                                                                                                                                                                            |
| [Font.Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#) | [setFontVariationSettings](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#setFontVariationSettings(kotlin.Array))`(`axes:` `[Array](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)<[FontVariationAxis](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontVariationAxis)!>?`)` Sets the font variation settings. |
| [Font.Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#) | [setFontVariationSettings](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#setFontVariationSettings(kotlin.String))`(`variationSettings:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?`)` Sets the font variation settings.                                                                                                |
| [Font.Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#) | [setSlant](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#setSlant(kotlin.Int))`(`slant:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Sets italic information of the font.                                                                                                                                                   |
| [Font.Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#) | [setTtcIndex](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#setTtcIndex(kotlin.Int))`(`ttcIndex:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Sets an index of the font collection.                                                                                                                                         |
| [Font.Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#) | [setWeight](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#setWeight(kotlin.Int))`(`weight:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Sets weight of the font.                                                                                                                                                            |

## Public constructors

### Builder

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder(
    am: AssetManager, 
    path: String)
```

Constructs a builder from an asset manager and a file path in an asset directory.

|                                                                                 Parameters                                                                                 ||
|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `am`   | [AssetManager](https://developer.android.com/reference/kotlin/android/content/res/AssetManager.html#):the application's asset manager This value cannot be`null`.  |
| `path` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):the file name of the font data in the asset directory This value cannot be`null`. |

### Builder

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder(
    res: Resources, 
    resId: Int)
```

Constructs a builder from resources. Resource ID must points the font file. XML font can not be used here.

|                                                                               Parameters                                                                               ||
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `res`   | [Resources](https://developer.android.com/reference/kotlin/android/content/res/Resources.html#):the resource of this application. This value cannot be`null`. |
| `resId` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the resource ID of font file.                                                      |

### Builder

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder(font: Font)
```

Constructs a builder from existing Font instance.

|                                                                Parameters                                                                 ||
|--------|-----------------------------------------------------------------------------------------------------------------------------------|
| `font` | [Font](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font):the font instance. This value cannot be`null`. |

### Builder

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder(fd: ParcelFileDescriptor)
```

Constructs a builder with a file descriptor.

|                                                                            Parameters                                                                            ||
|------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `fd` | [ParcelFileDescriptor](https://developer.android.com/reference/kotlin/android/os/ParcelFileDescriptor.html#):a file descriptor This value cannot be`null`. |

### Builder

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder(
    fd: ParcelFileDescriptor, 
    offset: Long, 
    size: Long)
```

Constructs a builder with a file descriptor.

|                                                                                     Parameters                                                                                     ||
|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `fd`     | [ParcelFileDescriptor](https://developer.android.com/reference/kotlin/android/os/ParcelFileDescriptor.html#):a file descriptor This value cannot be`null`.               |
| `offset` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html):an offset to of the font data in the file Value is 0 or greater                             |
| `size`   | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html):a size of the font data. If -1 is passed, use until end of the file. Value is -1 or greater |

### Builder

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder(path: File)
```

Constructs a builder with a file path.

|                                                                 Parameters                                                                 ||
|--------|------------------------------------------------------------------------------------------------------------------------------------|
| `path` | [File](https://developer.android.com/reference/kotlin/java/io/File.html#):a file path to the font file This value cannot be`null`. |

### Builder

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder(buffer: ByteBuffer)
```

Constructs a builder with a byte buffer. Note that only direct buffer can be used as the source of font data.

|                                                                        Parameters                                                                         ||
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `buffer` | [ByteBuffer](https://developer.android.com/reference/kotlin/java/nio/ByteBuffer.html#):a byte buffer of a font data This value cannot be`null`. |

**See Also**

- [java.nio.ByteBuffer#allocateDirect(int)](https://developer.android.com/reference/kotlin/java/nio/ByteBuffer.html#allocateDirect(kotlin.Int))

## Public methods

### build

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun build(): Font
```

Creates the font based on the configured values.

|                                                             Return                                                              ||
|------------------------------------------------------------------------------------|---------------------------------------------|
| [Font](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font) | the Font object This value cannot be`null`. |

### setFontVariationSettings

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setFontVariationSettings(axes: Array<FontVariationAxis!>?): Font.Builder
```

Sets the font variation settings.

|                                                                                                                                    Parameters                                                                                                                                     ||
|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `axes` | [Array](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)\<[FontVariationAxis](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontVariationAxis)!\>?:an array of font variation axis tag-value pairs This value may be`null`. |

|                                                                    Return                                                                     ||
|-----------------------------------------------------------------------------------------------------|------------------------------------------|
| [Font.Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#) | this builder This value cannot be`null`. |

### setFontVariationSettings

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setFontVariationSettings(variationSettings: String?): Font.Builder
```

Sets the font variation settings.

|                                                                                                                                                        Parameters                                                                                                                                                         ||
|---------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `variationSettings` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?:see[FontVariationAxis.fromFontVariationSettings(String)](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontVariationAxis#fromFontVariationSettings(kotlin.String))This value may be`null`. |

|                                                                    Return                                                                     ||
|-----------------------------------------------------------------------------------------------------|------------------------------------------|
| [Font.Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#) | this builder This value cannot be`null`. |

|                                              Exceptions                                              ||
|--------------------------------------|----------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | If given string is not a valid font variation settings format. |

### setSlant

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setSlant(slant: Int): Font.Builder
```

Sets italic information of the font. Tells the system the style of the given font. If this function is not called, the system will resolve the style by reading font tables. For example, if you want to use italic font as upright font, call`setSlant(FontStyle.FONT_SLANT_UPRIGHT)`explicitly.

|                                                                                                                                                                                                               Parameters                                                                                                                                                                                                               ||
|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `slant` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):Value is[android.graphics.fonts.FontStyle#FONT_SLANT_UPRIGHT](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_SLANT_UPRIGHT:kotlin.Int), or[android.graphics.fonts.FontStyle#FONT_SLANT_ITALIC](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_SLANT_ITALIC:kotlin.Int) |

|                                                                    Return                                                                     ||
|-----------------------------------------------------------------------------------------------------|------------------------------------------|
| [Font.Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#) | this builder This value cannot be`null`. |

### setTtcIndex

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setTtcIndex(ttcIndex: Int): Font.Builder
```

Sets an index of the font collection. See[android.R.attr#ttcIndex](https://developer.android.com/reference/kotlin/android/R.attr.html#ttcIndex:kotlin.Int).

|                                                                                                           Parameters                                                                                                           ||
|------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `ttcIndex` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):An index of the font collection. If the font source is not font collection, do not call this method or specify 0. Value is 0 or greater |

|                                                                    Return                                                                     ||
|-----------------------------------------------------------------------------------------------------|------------------------------------------|
| [Font.Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#) | this builder This value cannot be`null`. |

### setWeight

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setWeight(weight: Int): Font.Builder
```

Sets weight of the font. Tells the system the weight of the given font. If this function is not called, the system will resolve the weight value by reading font tables. Here are pairs of the common names and their values.

<br />

<br />

| Value |           Name            |                                                                   Android Definition                                                                    |
|-------|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| 100   | Thin                      | [FontStyle.FONT_WEIGHT_THIN](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_THIN:kotlin.Int)               |
| 200   | Extra Light (Ultra Light) | [FontStyle.FONT_WEIGHT_EXTRA_LIGHT](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_EXTRA_LIGHT:kotlin.Int) |
| 300   | Light                     | [FontStyle.FONT_WEIGHT_LIGHT](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_LIGHT:kotlin.Int)             |
| 400   | Normal (Regular)          | [FontStyle.FONT_WEIGHT_NORMAL](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_NORMAL:kotlin.Int)           |
| 500   | Medium                    | [FontStyle.FONT_WEIGHT_MEDIUM](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_MEDIUM:kotlin.Int)           |
| 600   | Semi Bold (Demi Bold)     | [FontStyle.FONT_WEIGHT_SEMI_BOLD](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_SEMI_BOLD:kotlin.Int)     |
| 700   | Bold                      | [FontStyle.FONT_WEIGHT_BOLD](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_BOLD:kotlin.Int)               |
| 800   | Extra Bold (Ultra Bold)   | [FontStyle.FONT_WEIGHT_EXTRA_BOLD](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_EXTRA_BOLD:kotlin.Int)   |
| 900   | Black (Heavy)             | [FontStyle.FONT_WEIGHT_BLACK](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_BLACK:kotlin.Int)             |

|                                                                                                                                                                                                                          Parameters                                                                                                                                                                                                                          ||
|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `weight` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):a weight value Value is between[android.graphics.fonts.FontStyle#FONT_WEIGHT_MIN](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_MIN:kotlin.Int)and[android.graphics.fonts.FontStyle#FONT_WEIGHT_MAX](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_MAX:kotlin.Int)inclusive |

|                                                                    Return                                                                     ||
|-----------------------------------------------------------------------------------------------------|------------------------------------------|
| [Font.Builder](https://developer.android.com/reference/kotlin/android/graphics/fonts/Font.Builder#) | this builder This value cannot be`null`. |

**See Also**

- [android.graphics.fonts.FontStyle#FONT_WEIGHT_THIN](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_THIN:kotlin.Int)
- [android.graphics.fonts.FontStyle#FONT_WEIGHT_EXTRA_LIGHT](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_EXTRA_LIGHT:kotlin.Int)
- [android.graphics.fonts.FontStyle#FONT_WEIGHT_LIGHT](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_LIGHT:kotlin.Int)
- [android.graphics.fonts.FontStyle#FONT_WEIGHT_NORMAL](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_NORMAL:kotlin.Int)
- [android.graphics.fonts.FontStyle#FONT_WEIGHT_MEDIUM](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_MEDIUM:kotlin.Int)
- [android.graphics.fonts.FontStyle#FONT_WEIGHT_SEMI_BOLD](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_SEMI_BOLD:kotlin.Int)
- [android.graphics.fonts.FontStyle#FONT_WEIGHT_BOLD](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_BOLD:kotlin.Int)
- [android.graphics.fonts.FontStyle#FONT_WEIGHT_EXTRA_BOLD](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_EXTRA_BOLD:kotlin.Int)
- [android.graphics.fonts.FontStyle#FONT_WEIGHT_BLACK](https://developer.android.com/reference/kotlin/android/graphics/fonts/FontStyle#FONT_WEIGHT_BLACK:kotlin.Int)