# LayoutElementBuilders.FontStyle.Builder

Artifact: [androidx.wear.protolayout:protolayout](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/LayoutElementBuilders.java+class:androidx.wear.protolayout.LayoutElementBuilders.FontStyle.Builder) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

*** ** * ** ***

<br />

```
class LayoutElementBuilders.FontStyle.Builder
```

<br />

*** ** * ** ***

Builder for `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle`

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#Builder()()` Creates an instance of `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder`. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle` | `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#build()()` Builds an instance from accumulated values. |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder` | `@https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 0) https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setColor(androidx.wear.protolayout.ColorBuilders.ColorProp)(color: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ColorBuilders.ColorProp)` Sets the text color. |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder` | `@https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 0) https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setItalic(boolean)(italic: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether the text should be rendered in a italic typeface. |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder` | `@https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 0) https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setItalic(androidx.wear.protolayout.TypeBuilders.BoolProp)(italic: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/TypeBuilders.BoolProp)` Sets whether the text should be rendered in a italic typeface. |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder` | `@https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 0) https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setLetterSpacing(androidx.wear.protolayout.DimensionBuilders.EmProp)(letterSpacing: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/DimensionBuilders.EmProp)` Sets the text letter-spacing. |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder` | `@https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 400) https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setPreferredFontFamilies(java.lang.String,java.lang.String...)(fontFamily: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, fallbacks: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>)` Sets the preferred font families for this `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle`. |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder` | `@https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 400) https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setSettings(androidx.wear.protolayout.LayoutElementBuilders.FontSetting...)(settings: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontSetting!>)` Sets the collection of font settings to be applied. |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder` | `@https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 0) https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setSize(androidx.wear.protolayout.DimensionBuilders.SpProp)(size: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/DimensionBuilders.SpProp)` Sets the size of the font, in scaled pixels (sp). |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder` | `@https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 300) @https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/ProtoLayoutExperimental https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setSizes(int...)( sizes: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) @https://developer.android.com/reference/kotlin/androidx/annotation/Dimension(unit = https://developer.android.com/reference/kotlin/androidx/annotation/Dimension.SP) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html> )` Sets the available sizes of the font, in scaled pixels (sp). |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder` | `@https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 0) https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setUnderline(boolean)(underline: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether the text should be rendered with an underline. |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder` | `@https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 0) https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setUnderline(androidx.wear.protolayout.TypeBuilders.BoolProp)(underline: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/TypeBuilders.BoolProp)` Sets whether the text should be rendered with an underline. |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder` | `@https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 0) @https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/ProtoLayoutExperimental https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setVariant(int)(variant: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the variant of a font. |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder` | `@https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 0) @https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/ProtoLayoutExperimental https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setVariant(androidx.wear.protolayout.LayoutElementBuilders.FontVariantProp)(variant: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontVariantProp)` Sets the variant of a font. |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder` | `@https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 0) https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setWeight(int)(weight: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the weight of the font. |
| `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder` | `@https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 0) https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setWeight(androidx.wear.protolayout.LayoutElementBuilders.FontWeightProp)(weight: https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontWeightProp)` Sets the weight of the font. |

## Public constructors

### Builder

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
Builder()
```

Creates an instance of `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder`.

## Public functions

### build

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
fun build(): LayoutElementBuilders.FontStyle
```

Builds an instance from accumulated values.

### setColor

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
@RequiresSchemaVersion(major = 1, minor = 0)
fun setColor(color: ColorBuilders.ColorProp): LayoutElementBuilders.FontStyle.Builder
```

Sets the text color. If not defined, defaults to white.

While this field is statically accessible from 1.0, it's only bindable since version 1.2 and renderers supporting version 1.2 will use the dynamic value (if set).

### setItalic

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
@RequiresSchemaVersion(major = 1, minor = 0)
fun setItalic(italic: Boolean): LayoutElementBuilders.FontStyle.Builder
```

Sets whether the text should be rendered in a italic typeface. If not specified, defaults to "false".

### setItalic

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
@RequiresSchemaVersion(major = 1, minor = 0)
fun setItalic(italic: TypeBuilders.BoolProp): LayoutElementBuilders.FontStyle.Builder
```

Sets whether the text should be rendered in a italic typeface. If not specified, defaults to "false".

Note that this field only supports static values.

### setLetterSpacing

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
@RequiresSchemaVersion(major = 1, minor = 0)
fun setLetterSpacing(letterSpacing: DimensionBuilders.EmProp): LayoutElementBuilders.FontStyle.Builder
```

Sets the text letter-spacing. Positive numbers increase the space between letters while negative numbers tighten the space. If not specified, defaults to 0.

### setPreferredFontFamilies

```
@RequiresSchemaVersion(major = 1, minor = 400)
fun setPreferredFontFamilies(fontFamily: String, fallbacks: Array<String!>): LayoutElementBuilders.FontStyle.Builder
```

Sets the preferred font families for this `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle`.

For example, preferring default system variable font with default non variable system font as a fallback.

If the given font family is not available on a device, the fallback values will be attempted to use, in order in which they are given.

Renderer support for values outside of the given constants (`https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle#ROBOTO_FONT()` or `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle#ROBOTO_FLEX_FONT()`) is not guaranteed for all devices.

If not set, default system font will be used.

| Parameters |
|---|---|
| `fontFamily: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | preferred font family name to be used if available |
| `fallbacks: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>` | the ordered list of fallback font family to attempt to use if the preferred font family is not available. |

### setSettings

```
@RequiresSchemaVersion(major = 1, minor = 400)
fun setSettings(settings: Array<LayoutElementBuilders.FontSetting!>): LayoutElementBuilders.FontStyle.Builder
```

Sets the collection of font settings to be applied. If more than one Setting with the same axis tag is added, the first one will be used.

Any previously added settings will be cleared.

Supported settings depend on the font used and renderer version. If this is used with the variable fonts on renderers supporting 1.4, `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontSetting#weight(int)` and `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontSetting#width(float)` setting will always be available.

Consider providing a fallback values with `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setWeight(androidx.wear.protolayout.LayoutElementBuilders.FontWeightProp)` for devices that don't support variable fonts. For example, using `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders#FONT_WEIGHT_MEDIUM()` for weight axis with value greater or equal to `500`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the number of the given Setting is larger than 10. |

### setSize

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
@RequiresSchemaVersion(major = 1, minor = 0)
fun setSize(size: DimensionBuilders.SpProp): LayoutElementBuilders.FontStyle.Builder
```

Sets the size of the font, in scaled pixels (sp). If not specified, defaults to the size of the system's "body" font.

Any previously added values with this method or `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setSizes(int...)` will be cleared.

### setSizes

```
@RequiresSchemaVersion(major = 1, minor = 300)
@ProtoLayoutExperimental
fun setSizes(
    sizes: @IntRange(from = 1) @Dimension(unit = Dimension.SP) IntArray<Int>
): LayoutElementBuilders.FontStyle.Builder
```

Sets the available sizes of the font, in scaled pixels (sp). If not specified, defaults to the size of the system's "body" font.

If more than one size is specified and this `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle` is applied to a `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.Text` element with static text, the text size will be automatically picked from the provided sizes to try to perfectly fit within its parent bounds. In other words, the largest size from the specified preset sizes that can fit the most text within the parent bounds will be used.

The specified sizes don't have to be sorted, but they need to contain only positive values. The maximum number of sizes used is limited to 10.

Note that, if multiple sizes are set, the parent of the `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.Text` element this corresponds to shouldn't have its width and height set to wrapped, as it can lead to unexpected results.

If this `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle` is set to any other element besides `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.Text` or that `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.Text` element has dynamic field, only the last added size will be used.

Any previously added values with this method or `https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setSize(androidx.wear.protolayout.DimensionBuilders.SpProp)` will be cleared.

While this field is accessible from 1.0 as singular, it only accepts multiple values since version 1.3 and renderers supporting version 1.3 will use the multiple values to automatically scale text. Renderers who don't support this version will use the last size among multiple values.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the number of available sizes is larger than 10 or one of the sizes is not a positive value. |

### setUnderline

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
@RequiresSchemaVersion(major = 1, minor = 0)
fun setUnderline(underline: Boolean): LayoutElementBuilders.FontStyle.Builder
```

Sets whether the text should be rendered with an underline. If not specified, defaults to "false".

### setUnderline

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
@RequiresSchemaVersion(major = 1, minor = 0)
fun setUnderline(underline: TypeBuilders.BoolProp): LayoutElementBuilders.FontStyle.Builder
```

Sets whether the text should be rendered with an underline. If not specified, defaults to "false".

Note that this field only supports static values.

### setVariant

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
@RequiresSchemaVersion(major = 1, minor = 0)
@ProtoLayoutExperimental
fun setVariant(variant: Int): LayoutElementBuilders.FontStyle.Builder
```

Sets the variant of a font. Some renderers may use different fonts for title and body text, which can be selected using this field. If not specified, defaults to "body".

### setVariant

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
@RequiresSchemaVersion(major = 1, minor = 0)
@ProtoLayoutExperimental
fun setVariant(variant: LayoutElementBuilders.FontVariantProp): LayoutElementBuilders.FontStyle.Builder
```

Sets the variant of a font. Some renderers may use different fonts for title and body text, which can be selected using this field. If not specified, defaults to "body".

### setWeight

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
@RequiresSchemaVersion(major = 1, minor = 0)
fun setWeight(weight: Int): LayoutElementBuilders.FontStyle.Builder
```

Sets the weight of the font. If the provided value is not supported on a platform, the nearest supported value will be used. If not defined, or when set to an invalid value, defaults to "normal".

### setWeight

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
@RequiresSchemaVersion(major = 1, minor = 0)
fun setWeight(weight: LayoutElementBuilders.FontWeightProp): LayoutElementBuilders.FontStyle.Builder
```

Sets the weight of the font. If the provided value is not supported on a platform, the nearest supported value will be used. If not defined, or when set to an invalid value, defaults to "normal".