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/Typeface.CustomFallbackBuilder#pubctors) \| [Methods](https://developer.android.com/reference/android/graphics/Typeface.CustomFallbackBuilder#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/graphics/Typeface.CustomFallbackBuilder#inhmethods)

# Typeface.CustomFallbackBuilder

*** ** * ** ***

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

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

<br />

*** ** * ** ***

A builder class for creating new Typeface instance. There are two font fallback mechanisms, custom font fallback and system font fallback. The custom font fallback is a simple ordered list. The text renderer tries to see if it can render a character with the first font and if that font does not support the character, try next one and so on. It will keep trying until end of the custom fallback chain. The maximum length of the custom fallback chain is 64. The system font fallback is a system pre-defined fallback chain. The system fallback is processed only when no matching font is found in the custom font fallback.

Examples, 1) Create Typeface from single ttf file.


    Font font = new Font.Builder("your_font_file.ttf").build();
    FontFamily family = new FontFamily.Builder(font).build();
    Typeface typeface = new Typeface.CustomFallbackBuilder(family).build();

2) Create Typeface from multiple font files and select bold style by default.


    Font regularFont = new Font.Builder("regular.ttf").build();
    Font boldFont = new Font.Builder("bold.ttf").build();
    FontFamily family = new FontFamily.Builder(regularFont)
        .addFont(boldFont).build();
    Typeface typeface = new Typeface.CustomFallbackBuilder(family)
        .setWeight(Font.FONT_WEIGHT_BOLD)  // Set bold style as the default style.
                                           // If the font family doesn't have bold style font,
                                           // system will select the closest font.
        .build();

3) Create Typeface from single ttf file and if that font does not have glyph for the characters, use "serif" font family instead.


    Font font = new Font.Builder("your_font_file.ttf").build();
    FontFamily family = new FontFamily.Builder(font).build();
    Typeface typeface = new Typeface.CustomFallbackBuilder(family)
        .setSystemFallback("serif")  // Set serif font family as the fallback.
        .build();

4) Create Typeface from single ttf file and set another ttf file for the fallback.


    Font font = new Font.Builder("English.ttf").build();
    FontFamily family = new FontFamily.Builder(font).build();

    Font fallbackFont = new Font.Builder("Arabic.ttf").build();
    FontFamily fallbackFamily = new FontFamily.Builder(fallbackFont).build();
    Typeface typeface = new Typeface.CustomFallbackBuilder(family)
        .addCustomFallback(fallbackFamily)  // Specify fallback family.
        .setSystemFallback("serif")  // Set serif font family as the fallback.
        .build();

<br />

<br />

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/graphics/Typeface.CustomFallbackBuilder#CustomFallbackBuilder(android.graphics.fonts.FontFamily)(https://developer.android.com/reference/android/graphics/fonts/FontFamily family) ` Constructs a builder with a font family. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/graphics/Typeface.CustomFallbackBuilder` | ` https://developer.android.com/reference/android/graphics/Typeface.CustomFallbackBuilder#addCustomFallback(android.graphics.fonts.FontFamily)(https://developer.android.com/reference/android/graphics/fonts/FontFamily family) ` Append a font family to the end of the custom font fallback. |
| ` https://developer.android.com/reference/android/graphics/Typeface` | ` https://developer.android.com/reference/android/graphics/Typeface.CustomFallbackBuilder#build()() ` Create the Typeface based on the configured values. |
| ` static int` | ` https://developer.android.com/reference/android/graphics/Typeface.CustomFallbackBuilder#getMaxCustomFallbackCount()() ` Returns the maximum capacity of custom fallback families. |
| ` https://developer.android.com/reference/android/graphics/Typeface.CustomFallbackBuilder` | ` https://developer.android.com/reference/android/graphics/Typeface.CustomFallbackBuilder#setStyle(android.graphics.fonts.FontStyle)(https://developer.android.com/reference/android/graphics/fonts/FontStyle style) ` Sets a font style of the Typeface. |
| ` https://developer.android.com/reference/android/graphics/Typeface.CustomFallbackBuilder` | ` https://developer.android.com/reference/android/graphics/Typeface.CustomFallbackBuilder#setSystemFallback(java.lang.String)(https://developer.android.com/reference/java/lang/String familyName) ` Sets a system fallback by name. |

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

### CustomFallbackBuilder

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

```
public CustomFallbackBuilder (FontFamily family)
```

Constructs a builder with a font family.

<br />

| Parameters ||
|---|---|
| `family` | `FontFamily`: a family object. This value cannot be `null`. <br /> |

## Public methods

### addCustomFallback

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

```
public Typeface.CustomFallbackBuilder addCustomFallback (FontFamily family)
```

Append a font family to the end of the custom font fallback. You can set up to 64 custom fallback families including the first font family you passed to the constructor. For more information about fallback, see class description.

<br />

| Parameters ||
|---|---|
| `family` | `FontFamily`: a fallback family. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Typeface.CustomFallbackBuilder` | This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if you give more than 64 custom fallback families |

### build

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

```
public Typeface build ()
```

Create the Typeface based on the configured values.

<br />

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

### getMaxCustomFallbackCount

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

```
public static int getMaxCustomFallbackCount ()
```

Returns the maximum capacity of custom fallback families. This includes the first font family passed to the constructor. It is guaranteed that the value will be greater than or equal to 64.

<br />

| Returns ||
|---|---|
| `int` | the maximum number of font families for the custom fallback. Value is 64 or greater <br /> |

### setStyle

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

```
public Typeface.CustomFallbackBuilder setStyle (FontStyle style)
```

Sets a font style of the Typeface. If the font family doesn't have a font of given style, system will select the closest font from font family. For example, if a font family has fonts of 300 weight and 700 weight then setWeight(400) is called, system will select the font of 300 weight.

<br />

| Parameters ||
|---|---|
| `style` | `FontStyle`: a font style. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Typeface.CustomFallbackBuilder` | This value cannot be `null`. <br /> |

### setSystemFallback

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

```
public Typeface.CustomFallbackBuilder setSystemFallback (String familyName)
```

Sets a system fallback by name. You can specify generic font family names or OEM specific family names. If the system don't have a specified fallback, the default fallback is used instead. For more information about generic font families, see [CSS specification](https://www.w3.org/TR/css-fonts-4/#generic-font-families) For more information about fallback, see class description.

<br />

| Parameters ||
|---|---|
| `familyName` | `String`: a family name to be used for fallback if the provided fonts can not be used. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Typeface.CustomFallbackBuilder` | This value cannot be `null`. <br /> |