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

# Typeface.Builder

*** ** * ** ***

` public static final class Typeface.Builder `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

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

<br />

*** ** * ** ***

A builder class for creating new Typeface instance.

Examples, 1) Create Typeface from ttf file.


    Typeface.Builder builder = new Typeface.Builder("your_font_file.ttf");
    Typeface typeface = builder.build();

2) Create Typeface from ttc file in assets directory.


    Typeface.Builder builder = new Typeface.Builder(getAssets(), "your_font_file.ttc");
    builder.setTtcIndex(2);  // Set index of font collection.
    Typeface typeface = builder.build();

3) Create Typeface with variation settings.


    Typeface.Builder builder = new Typeface.Builder("your_font_file.ttf");
    builder.setFontVariationSettings("'wght' 700, 'slnt' 20, 'ital' 1");
    builder.setWeight(700);  // Tell the system that this is a bold font.
    builder.setItalic(true);  // Tell the system that this is an italic style font.
    Typeface typeface = builder.build();

<br />

<br />

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/graphics/Typeface.Builder#Builder(android.content.res.AssetManager,%20java.lang.String)(https://developer.android.com/reference/android/content/res/AssetManager assetManager, 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/Typeface.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/Typeface.Builder#Builder(java.io.FileDescriptor)(https://developer.android.com/reference/java/io/FileDescriptor fd) ` Constructs a builder with a file descriptor. |
| ` https://developer.android.com/reference/android/graphics/Typeface.Builder#Builder(java.lang.String)(https://developer.android.com/reference/java/lang/String path) ` Constructs a builder with a file path. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/graphics/Typeface` | ` https://developer.android.com/reference/android/graphics/Typeface.Builder#build()() ` Generates new Typeface from specified configuration. |
| ` https://developer.android.com/reference/android/graphics/Typeface.Builder` | ` https://developer.android.com/reference/android/graphics/Typeface.Builder#setFallback(java.lang.String)(https://developer.android.com/reference/java/lang/String familyName) ` Sets a fallback family name. |
| ` https://developer.android.com/reference/android/graphics/Typeface.Builder` | ` https://developer.android.com/reference/android/graphics/Typeface.Builder#setFontVariationSettings(java.lang.String)(https://developer.android.com/reference/java/lang/String variationSettings) ` Sets a font variation settings. |
| ` https://developer.android.com/reference/android/graphics/Typeface.Builder` | ` https://developer.android.com/reference/android/graphics/Typeface.Builder#setFontVariationSettings(android.graphics.fonts.FontVariationAxis[])(https://developer.android.com/reference/android/graphics/fonts/FontVariationAxis axes) ` Sets a font variation settings. |
| ` https://developer.android.com/reference/android/graphics/Typeface.Builder` | ` https://developer.android.com/reference/android/graphics/Typeface.Builder#setItalic(boolean)(boolean italic) ` Sets italic information of the font. |
| ` https://developer.android.com/reference/android/graphics/Typeface.Builder` | ` https://developer.android.com/reference/android/graphics/Typeface.Builder#setTtcIndex(int)(int ttcIndex) ` Sets an index of the font collection. |
| ` https://developer.android.com/reference/android/graphics/Typeface.Builder` | ` https://developer.android.com/reference/android/graphics/Typeface.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 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

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

<br />

| Parameters ||
|---|---|
| `assetManager` | `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 26](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`: The file object refers to the font file. This value cannot be `null`. <br /> |

### Builder

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

```
public Builder (FileDescriptor fd)
```

Constructs a builder with a file descriptor. Caller is responsible for closing the passed file descriptor after `https://developer.android.com/reference/android/graphics/Typeface.Builder#build()` is called.

<br />

| Parameters ||
|---|---|
| `fd` | `FileDescriptor`: The file descriptor. The passed fd must be mmap-able. This value cannot be `null`. <br /> |

### Builder

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

```
public Builder (String path)
```

Constructs a builder with a file path.

<br />

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

## Public methods

### build

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

```
public Typeface build ()
```

Generates new Typeface from specified configuration.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Typeface` | Newly created Typeface. May return null if some parameters are invalid. <br /> |

### setFallback

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

```
public Typeface.Builder setFallback (String familyName)
```

Sets a fallback family name. By specifying a fallback family name, a fallback Typeface will be returned if the `https://developer.android.com/reference/android/graphics/Typeface.Builder#build()` method fails to create a Typeface from the provided font. The fallback family will be resolved with the provided weight and italic information specified by `https://developer.android.com/reference/android/graphics/Typeface.Builder#setWeight(int)` and `https://developer.android.com/reference/android/graphics/Typeface.Builder#setItalic(boolean)`. If `https://developer.android.com/reference/android/graphics/Typeface.Builder#setWeight(int)` is not called, the fallback family keeps the default weight. Similarly, if `https://developer.android.com/reference/android/graphics/Typeface.Builder#setItalic(boolean)` is not called, the fallback family keeps the default italic information. For example, calling `builder.setFallback("sans-serif-light")` is equivalent to calling `builder.setFallback("sans-serif").setWeight(300)` in terms of fallback. The default weight and italic information are overridden by calling `https://developer.android.com/reference/android/graphics/Typeface.Builder#setWeight(int)` and `https://developer.android.com/reference/android/graphics/Typeface.Builder#setItalic(boolean)`. For example, if a Typeface is constructed using `builder.setFallback("sans-serif-light").setWeight(700)`, the fallback text will render as sans serif bold.

<br />

| Parameters ||
|---|---|
| `familyName` | `String`: A family name to be used for fallback if the provided font can not be used. By passing `null`, build() returns `null`. If `https://developer.android.com/reference/android/graphics/Typeface.Builder#setFallback(java.lang.String)` is not called on the builder, `null` is assumed. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Typeface.Builder` | <br /> |

### setFontVariationSettings

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

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

Sets a font variation settings.

<br />

| Parameters ||
|---|---|
| `variationSettings` | `String`: See `https://developer.android.com/reference/android/widget/TextView#setFontVariationSettings(java.lang.String)`. This value may be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Typeface.Builder` | <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 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Sets a 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/Typeface.Builder` | <br /> |

### setItalic

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

```
public Typeface.Builder setItalic (boolean italic)
```

Sets italic information of the font. Tells the system the style of the given font. If not provided, the system will resolve the style by reading font tables.

<br />

| Parameters ||
|---|---|
| `italic` | `boolean`: `true` if the font is italic. Otherwise `false`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Typeface.Builder` | <br /> |

### setTtcIndex

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

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

Sets an index of the font collection. See `https://developer.android.com/reference/android/R.attr#ttcIndex`. Can not be used for Typeface source. build() method will return null for invalid index.

<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/Typeface.Builder` | <br /> |

### setWeight

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

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

Sets weight of the font. Tells the system the weight of the given font. If not provided, the system will resolve the weight value by reading font tables.

<br />

| Parameters ||
|---|---|
| `weight` | `int`: a weight value. Value is between 1 and 1000 inclusive <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Typeface.Builder` | <br /> |