Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/graphics/fonts/Font.Builder#pubctors) \| [Methods](https://developer.android.com/reference/android/graphics/fonts/Font.Builder#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/graphics/fonts/Font.Builder#inhmethods)

# Font.Builder

*** ** * ** ***


`
public
static
final

class
Font.Builder
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.graphics.fonts.Font.Builder |

<br />

*** ** * ** ***

A builder class for creating new Font.

## Summary

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

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/graphics/fonts/Font` | ` https://developer.android.com/reference/android/graphics/fonts/Font.Builder#build()() ` Creates the font based on the configured values. |
| ` https://developer.android.com/reference/android/graphics/fonts/Font.Builder` | ` https://developer.android.com/reference/android/graphics/fonts/Font.Builder#setFontVariationSettings(java.lang.String)(https://developer.android.com/reference/java/lang/String variationSettings) ` Sets the font variation settings. |
| ` https://developer.android.com/reference/android/graphics/fonts/Font.Builder` | ` https://developer.android.com/reference/android/graphics/fonts/Font.Builder#setFontVariationSettings(android.graphics.fonts.FontVariationAxis[])(https://developer.android.com/reference/android/graphics/fonts/FontVariationAxis axes) ` Sets the font variation settings. |
| ` https://developer.android.com/reference/android/graphics/fonts/Font.Builder` | ` https://developer.android.com/reference/android/graphics/fonts/Font.Builder#setSlant(int)(int slant) ` Sets italic information of the font. |
| ` https://developer.android.com/reference/android/graphics/fonts/Font.Builder` | ` https://developer.android.com/reference/android/graphics/fonts/Font.Builder#setTtcIndex(int)(int ttcIndex) ` Sets an index of the font collection. |
| ` https://developer.android.com/reference/android/graphics/fonts/Font.Builder` | ` https://developer.android.com/reference/android/graphics/fonts/Font.Builder#setWeight(int)(int weight) ` Sets weight of the font. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public constructors

### Builder

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

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

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

<br />

| Parameters ||
|---|---|
| `am` | `AssetManager`: the application's asset manager. This value cannot be `null`. <br /> |
| `path` | `String`: the file name of the font data in the asset directory. This value cannot be `null`. <br /> |

### Builder

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

```
public Builder (Resources res, 
                int resId)
```

Constructs a builder from resources.

Resource ID must points the font file. XML font can not be used here.

<br />

| Parameters ||
|---|---|
| `res` | `Resources`: the resource of this application. This value cannot be `null`. <br /> |
| `resId` | `int`: the resource ID of font file. <br /> |

### Builder

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

```
public Builder (Font font)
```

Constructs a builder from existing Font instance.

<br />

| Parameters ||
|---|---|
| `font` | `Font`: the font instance. This value cannot be `null`. <br /> |

### Builder

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

```
public Builder (ParcelFileDescriptor fd)
```

Constructs a builder with a file descriptor.

<br />

| Parameters ||
|---|---|
| `fd` | `ParcelFileDescriptor`: a file descriptor. This value cannot be `null`. <br /> |

### Builder

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

```
public Builder (ParcelFileDescriptor fd, 
                long offset, 
                long size)
```

Constructs a builder with a file descriptor.

This constructor immediately maps the font file into memory and closes the
provided file descriptor.

<br />

| Parameters ||
|---|---|
| `fd` | `ParcelFileDescriptor`: a file descriptor. This value cannot be `null`. <br /> |
| `offset` | `long`: an offset to of the font data in the file. Value is 0 or greater <br /> |
| `size` | `long`: a size of the font data. If -1 is passed, use until end of the file. Value is -1 or greater <br /> |

### Builder

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

```
public Builder (File path)
```

Constructs a builder with a file path.

<br />

| Parameters ||
|---|---|
| `path` | `File`: a file path to the font file. This value cannot be `null`. <br /> |

### Builder

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

```
public Builder (ByteBuffer buffer)
```

Constructs a builder with a byte buffer.

Note that only direct buffer can be used as the source of font data.

<br />

| Parameters ||
|---|---|
| `buffer` | `ByteBuffer`: a byte buffer of a font data. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/java/nio/ByteBuffer#allocateDirect(int)`

## Public methods

### build

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

```
public Font build ()
```

Creates the font based on the configured values.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/fonts/Font` | the Font object. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### setFontVariationSettings

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

```
public Font.Builder setFontVariationSettings (String variationSettings)
```

Sets the font variation settings.

<br />

| Parameters ||
|---|---|
| `variationSettings` | `String`: see `https://developer.android.com/reference/android/graphics/fonts/FontVariationAxis#fromFontVariationSettings(java.lang.String)` This value may be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/fonts/Font.Builder` | this builder. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | If given string is not a valid font variation settings format. |

### setFontVariationSettings

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

```
public Font.Builder setFontVariationSettings (FontVariationAxis[] axes)
```

Sets the font variation settings.

<br />

| Parameters ||
|---|---|
| `axes` | `FontVariationAxis`: an array of font variation axis tag-value pairs. This value may be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/fonts/Font.Builder` | this builder. This value cannot be `null`. <br /> |

### setSlant

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

```
public Font.Builder setSlant (int slant)
```

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.

<br />

| Parameters ||
|---|---|
| `slant` | `int`: Value is one of the following: - `https://developer.android.com/reference/android/graphics/fonts/FontStyle#FONT_SLANT_UPRIGHT` - `https://developer.android.com/reference/android/graphics/fonts/FontStyle#FONT_SLANT_ITALIC` |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/fonts/Font.Builder` | this builder. This value cannot be `null`. <br /> |

### setTtcIndex

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

```
public Font.Builder setTtcIndex (int ttcIndex)
```

Sets an index of the font collection. See `https://developer.android.com/reference/android/R.attr#ttcIndex`.

<br />

| Parameters ||
|---|---|
| `ttcIndex` | `int`: 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 <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/fonts/Font.Builder` | this builder. This value cannot be `null`. <br /> |

### setWeight

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

```
public Font.Builder setWeight (int weight)
```

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 />

<br />

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

| Parameters ||
|---|---|
| `weight` | `int`: a weight value. Value is between `https://developer.android.com/reference/android/graphics/fonts/FontStyle#FONT_WEIGHT_MIN` and `https://developer.android.com/reference/android/graphics/fonts/FontStyle#FONT_WEIGHT_MAX` inclusive <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/fonts/Font.Builder` | this builder. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/graphics/fonts/FontStyle#FONT_WEIGHT_THIN`
- `https://developer.android.com/reference/android/graphics/fonts/FontStyle#FONT_WEIGHT_EXTRA_LIGHT`
- `https://developer.android.com/reference/android/graphics/fonts/FontStyle#FONT_WEIGHT_LIGHT`
- `https://developer.android.com/reference/android/graphics/fonts/FontStyle#FONT_WEIGHT_NORMAL`
- `https://developer.android.com/reference/android/graphics/fonts/FontStyle#FONT_WEIGHT_MEDIUM`
- `https://developer.android.com/reference/android/graphics/fonts/FontStyle#FONT_WEIGHT_SEMI_BOLD`
- `https://developer.android.com/reference/android/graphics/fonts/FontStyle#FONT_WEIGHT_BOLD`
- `https://developer.android.com/reference/android/graphics/fonts/FontStyle#FONT_WEIGHT_EXTRA_BOLD`
- `https://developer.android.com/reference/android/graphics/fonts/FontStyle#FONT_WEIGHT_BLACK`