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

```
public final class LayoutElementBuilders.FontStyle.Builder
```

<br />

*** ** * ** ***

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

## Summary

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

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

```
public Builder()
```

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

## Public methods

### build

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

```
public @NonNull LayoutElementBuilders.FontStyle build()
```

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)
public @NonNull LayoutElementBuilders.FontStyle.Builder setColor(@NonNull ColorBuilders.ColorProp color)
```

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)
public @NonNull LayoutElementBuilders.FontStyle.Builder setItalic(boolean italic)
```

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)
public @NonNull LayoutElementBuilders.FontStyle.Builder setItalic(@NonNull TypeBuilders.BoolProp italic)
```

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)
public @NonNull LayoutElementBuilders.FontStyle.Builder setLetterSpacing(@NonNull DimensionBuilders.EmProp letterSpacing)
```

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)
public @NonNull LayoutElementBuilders.FontStyle.Builder setPreferredFontFamilies(
    @NonNull String fontFamily,
    @NonNull String[] fallbacks
)
```

Sets the preferred font families for this `https://developer.android.com/reference/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/androidx/wear/protolayout/LayoutElementBuilders.FontStyle#ROBOTO_FONT()` or `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.FontStyle#ROBOTO_FLEX_FONT()`) is not guaranteed for all devices.

If not set, default system font will be used.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html fontFamily` | preferred font family name to be used if available |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html String[] fallbacks` | 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)
public @NonNull LayoutElementBuilders.FontStyle.Builder setSettings(@NonNull LayoutElementBuilders.FontSetting[] settings)
```

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/androidx/wear/protolayout/LayoutElementBuilders.FontSetting#weight(int)` and `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.FontSetting#width(float)` setting will always be available.

Consider providing a fallback values with `https://developer.android.com/reference/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/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)
public @NonNull LayoutElementBuilders.FontStyle.Builder setSize(@NonNull DimensionBuilders.SpProp size)
```

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/androidx/wear/protolayout/LayoutElementBuilders.FontStyle.Builder#setSizes(int...)` will be cleared.

### setSizes

```
@RequiresSchemaVersion(major = 1, minor = 300)
@ProtoLayoutExperimental
public @NonNull LayoutElementBuilders.FontStyle.Builder setSizes(
    @IntRange(from = 1) @Dimension(unit = Dimension.SP) @NonNull int[] sizes
)
```

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/androidx/wear/protolayout/LayoutElementBuilders.FontStyle` is applied to a `https://developer.android.com/reference/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/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/androidx/wear/protolayout/LayoutElementBuilders.FontStyle` is set to any other element besides `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.Text` or that `https://developer.android.com/reference/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/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)
public @NonNull LayoutElementBuilders.FontStyle.Builder setUnderline(boolean underline)
```

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)
public @NonNull LayoutElementBuilders.FontStyle.Builder setUnderline(@NonNull TypeBuilders.BoolProp underline)
```

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
public @NonNull LayoutElementBuilders.FontStyle.Builder setVariant(int variant)
```

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
public @NonNull LayoutElementBuilders.FontStyle.Builder setVariant(@NonNull LayoutElementBuilders.FontVariantProp variant)
```

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)
public @NonNull LayoutElementBuilders.FontStyle.Builder setWeight(int weight)
```

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)
public @NonNull LayoutElementBuilders.FontStyle.Builder setWeight(@NonNull LayoutElementBuilders.FontWeightProp weight)
```

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".