Stay organized with collections
Save and categorize content based on your preferences.
Builder
class Builder
A builder class for creating new FontFamily.
Summary
Public constructors |
Constructs a builder.
|
Public methods |
FontFamily.Builder |
Adds different style font to the builder.
|
FontFamily |
Build the font family
|
FontFamily? |
Build a variable font family that automatically adjust the `wght` and `ital` axes value for the requested weight/italic style values.
|
Public constructors
Builder
Builder(font: Font)
Constructs a builder.
Parameters |
font |
Font: a font This value cannot be null . |
Public methods
addFont
fun addFont(font: Font): FontFamily.Builder
Adds different style font to the builder. System will select the font if the text style is closest to the font. If the same style font is already added to the builder, this method will fail with IllegalArgumentException
. Note that system assumes all fonts bundled in FontFamily have the same coverage for the code points. For example, regular style font and bold style font must have the same code point coverage, otherwise some character may be shown as tofu.
Parameters |
font |
Font: a font This value cannot be null . |
build
fun build(): FontFamily
Build the font family
Return |
FontFamily |
a font family This value cannot be null . |
buildVariableFamily
fun buildVariableFamily(): FontFamily?
Build a variable font family that automatically adjust the `wght` and `ital` axes value for the requested weight/italic style values. To build a variable font family, added fonts must meet one of following conditions. If two font files are added, both font files must support `wght` axis and one font must support FontStyle.FONT_SLANT_UPRIGHT
and another font must support FontStyle.FONT_SLANT_ITALIC
. If the requested weight value is lower than minimum value of the supported `wght` axis, the minimum supported `wght` value is used. If the requested weight value is larger than maximum value of the supported `wght` axis, the maximum supported `wght` value is used. The weight values of the fonts are ignored. If one font file is added, that font must support the `wght` axis. If that font support `ital` axis, that `ital` value is set to 1 when the italic style is requested. If that font doesn't support `ital` axis, synthetic italic may be used. If the requested weight value is lower than minimum value of the supported `wght` axis, the minimum supported `wght` value is used. If the requested weight value is larger than maximum value of the supported `wght`axis, the maximum supported `wght` value is used. The weight value of the font is ignored. If none of the above conditions are met, the provided font files cannot be used for variable font family and this function returns null
. Even if this function returns null
, you can still use build()
method for creating FontFamily instance with manually specifying variation settings by using Font.Builder.setFontVariationSettings(String)
.
Return |
FontFamily? |
A variable font family. null if a variable font cannot be built from the given fonts. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# FontFamily.Builder\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nBuilder\n=======\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/graphics/fonts/FontFamily.Builder \"View this page in Java\") \n\n```\nclass Builder\n```\n\n|---|------------------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.graphics.fonts.FontFamily.Builder](#) |\n\nA builder class for creating new FontFamily.\n\nSummary\n-------\n\n| Public constructors ||\n|-------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [Builder](#Builder(android.graphics.fonts.Font))`(`font:` `[Font](/reference/kotlin/android/graphics/fonts/Font)`)` Constructs a builder. |\n\n| Public methods ||\n|--------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [FontFamily.Builder](#) | [addFont](#addFont(android.graphics.fonts.Font))`(`font:` `[Font](/reference/kotlin/android/graphics/fonts/Font)`)` Adds different style font to the builder. |\n| [FontFamily](/reference/kotlin/android/graphics/fonts/FontFamily) | [build](#build())`()` Build the font family |\n| [FontFamily](/reference/kotlin/android/graphics/fonts/FontFamily)? | [buildVariableFamily](#buildVariableFamily())`()` Build a variable font family that automatically adjust the \\`wght\\` and \\`ital\\` axes value for the requested weight/italic style values. |\n\nPublic constructors\n-------------------\n\n### Builder\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nBuilder(font: Font)\n```\n\nConstructs a builder.\n\n| Parameters ||\n|--------|--------------------------------------------------------------------------------------------|\n| `font` | [Font](/reference/kotlin/android/graphics/fonts/Font): a font This value cannot be `null`. |\n\nPublic methods\n--------------\n\n### addFont\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun addFont(font: Font): FontFamily.Builder\n```\n\nAdds different style font to the builder. System will select the font if the text style is closest to the font. If the same style font is already added to the builder, this method will fail with [IllegalArgumentException](../../../java/lang/IllegalArgumentException.html#). Note that system assumes all fonts bundled in FontFamily have the same coverage for the code points. For example, regular style font and bold style font must have the same code point coverage, otherwise some character may be shown as tofu.\n\n| Parameters ||\n|--------|--------------------------------------------------------------------------------------------|\n| `font` | [Font](/reference/kotlin/android/graphics/fonts/Font): a font This value cannot be `null`. |\n\n| Return ||\n|-------------------------|-------------------------------------------|\n| [FontFamily.Builder](#) | this builder This value cannot be `null`. |\n\n### build\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun build(): FontFamily\n```\n\nBuild the font family\n\n| Return ||\n|-------------------------------------------------------------------|--------------------------------------------|\n| [FontFamily](/reference/kotlin/android/graphics/fonts/FontFamily) | a font family This value cannot be `null`. |\n\n### buildVariableFamily\n\nAdded in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun buildVariableFamily(): FontFamily?\n```\n\nBuild a variable font family that automatically adjust the \\`wght\\` and \\`ital\\` axes value for the requested weight/italic style values. To build a variable font family, added fonts must meet one of following conditions. If two font files are added, both font files must support \\`wght\\` axis and one font must support [FontStyle.FONT_SLANT_UPRIGHT](/reference/kotlin/android/graphics/fonts/FontStyle#FONT_SLANT_UPRIGHT:kotlin.Int) and another font must support [FontStyle.FONT_SLANT_ITALIC](/reference/kotlin/android/graphics/fonts/FontStyle#FONT_SLANT_ITALIC:kotlin.Int). If the requested weight value is lower than minimum value of the supported \\`wght\\` axis, the minimum supported \\`wght\\` value is used. If the requested weight value is larger than maximum value of the supported \\`wght\\` axis, the maximum supported \\`wght\\` value is used. The weight values of the fonts are ignored. If one font file is added, that font must support the \\`wght\\` axis. If that font support \\`ital\\` axis, that \\`ital\\` value is set to 1 when the italic style is requested. If that font doesn't support \\`ital\\` axis, synthetic italic may be used. If the requested weight value is lower than minimum value of the supported \\`wght\\` axis, the minimum supported \\`wght\\` value is used. If the requested weight value is larger than maximum value of the supported \\`wght\\`axis, the maximum supported \\`wght\\` value is used. The weight value of the font is ignored. If none of the above conditions are met, the provided font files cannot be used for variable font family and this function returns `null`. Even if this function returns `null`, you can still use [build()](#build()) method for creating FontFamily instance with manually specifying variation settings by using [Font.Builder.setFontVariationSettings(String)](/reference/kotlin/android/graphics/fonts/Font.Builder#setFontVariationSettings(kotlin.String)).\n\n| Return ||\n|--------------------------------------------------------------------|---------------------------------------------------------------------------------------|\n| [FontFamily](/reference/kotlin/android/graphics/fonts/FontFamily)? | A variable font family. null if a variable font cannot be built from the given fonts. |"]]