Added in API level 29

Builder


class Builder
kotlin.Any
   ↳ android.graphics.fonts.Font.Builder

A builder class for creating new Font.

Summary

Public constructors

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

Builder(res: Resources, resId: Int)

Constructs a builder from resources.

Builder(font: Font)

Constructs a builder from existing Font instance.

Constructs a builder with a file descriptor.

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

Constructs a builder with a file descriptor.

Builder(path: File)

Constructs a builder with a file path.

Constructs a builder with a byte buffer.

Public methods
Font

Creates the font based on the configured values.

Font.Builder

Sets the font variation settings.

Font.Builder
setFontVariationSettings(variationSettings: String?)

Sets the font variation settings.

Font.Builder
setSlant(slant: Int)

Sets italic information of the font.

Font.Builder
setTtcIndex(ttcIndex: Int)

Sets an index of the font collection.

Font.Builder
setWeight(weight: Int)

Sets weight of the font.

Public constructors

Builder

Added in API level 29
Builder(
    am: AssetManager,
    path: String)

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

Parameters
am AssetManager: the application's asset manager This value cannot be null.
path String: the file name of the font data in the asset directory This value cannot be null.

Builder

Added in API level 29
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: the resource of this application. This value cannot be null.
resId Int: the resource ID of font file.

Builder

Added in API level 31
Builder(font: Font)

Constructs a builder from existing Font instance.

Parameters
font Font: the font instance. This value cannot be null.

Builder

Added in API level 29
Builder(fd: ParcelFileDescriptor)

Constructs a builder with a file descriptor.

Parameters
fd ParcelFileDescriptor: a file descriptor This value cannot be null.

Builder

Added in API level 29
Builder(
    fd: ParcelFileDescriptor,
    offset: Long,
    size: Long)

Constructs a builder with a file descriptor.

Parameters
fd ParcelFileDescriptor: a file descriptor This value cannot be null.
offset Long: an offset to of the font data in the file Value is 0 or greater
size Long: 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
Builder(path: File)

Constructs a builder with a file path.

Parameters
path File: a file path to the font file This value cannot be null.

Builder

Added in API level 29
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: a byte buffer of a font data This value cannot be null.

Public methods

build

Added in API level 29
fun build(): Font

Creates the font based on the configured values.

Return
Font the Font object This value cannot be null.

setFontVariationSettings

Added in API level 29
fun setFontVariationSettings(axes: Array<FontVariationAxis!>?): Font.Builder

Sets the font variation settings.

Parameters
axes Array<FontVariationAxis!>?: an array of font variation axis tag-value pairs This value may be null.
Return
Font.Builder this builder This value cannot be null.

setFontVariationSettings

Added in API level 29
fun setFontVariationSettings(variationSettings: String?): Font.Builder

Sets the font variation settings.

Parameters
variationSettings String?: see FontVariationAxis.fromFontVariationSettings(String) This value may be null.
Return
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
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: Value is android.graphics.fonts.FontStyle#FONT_SLANT_UPRIGHT, or android.graphics.fonts.FontStyle#FONT_SLANT_ITALIC
Return
Font.Builder this builder This value cannot be null.

setTtcIndex

Added in API level 29
fun setTtcIndex(ttcIndex: Int): Font.Builder

Sets an index of the font collection. See android.R.attr#ttcIndex.

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
Return
Font.Builder this builder This value cannot be null.

setWeight

Added in API level 29
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.

Value Name Android Definition
100 Thin FontStyle.FONT_WEIGHT_THIN
200 Extra Light (Ultra Light) FontStyle.FONT_WEIGHT_EXTRA_LIGHT
300 Light FontStyle.FONT_WEIGHT_LIGHT
400 Normal (Regular) FontStyle.FONT_WEIGHT_NORMAL
500 Medium FontStyle.FONT_WEIGHT_MEDIUM
600 Semi Bold (Demi Bold) FontStyle.FONT_WEIGHT_SEMI_BOLD
700 Bold FontStyle.FONT_WEIGHT_BOLD
800 Extra Bold (Ultra Bold) FontStyle.FONT_WEIGHT_EXTRA_BOLD
900 Black (Heavy) FontStyle.FONT_WEIGHT_BLACK
Parameters
weight Int: a weight value Value is between FontStyle.FONT_WEIGHT_MIN and FontStyle.FONT_WEIGHT_MAX inclusive
Return
Font.Builder this builder This value cannot be null.