# Text.Builder

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

*** ** * ** ***


```
public final class Text.Builder
```

<br />

*** ** * ** ***

Builder class for `https://developer.android.com/reference/androidx/wear/protolayout/material/Text`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder#Builder(android.content.Context,java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html text)` Creates a builder for a `https://developer.android.com/reference/androidx/wear/protolayout/material/Text` component with static text. |
| `https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder#Builder(android.content.Context,androidx.wear.protolayout.TypeBuilders.StringProp,androidx.wear.protolayout.TypeBuilders.StringLayoutConstraint)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/TypeBuilders.StringProp text, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/TypeBuilders.StringLayoutConstraint stringLayoutConstraint )` Creates a builder for a `https://developer.android.com/reference/androidx/wear/protolayout/material/Text`. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Text` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder#build()()` Constructs and returns `https://developer.android.com/reference/androidx/wear/protolayout/material/Text` with the provided content and look. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Text.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 color for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Text`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder#setItalic(boolean)(boolean italic)` Sets the text to be italic. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder#setMaxLines(int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) int maxLines)` Sets the maximum lines of text. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder#setModifiers(androidx.wear.protolayout.ModifiersBuilders.Modifiers)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/ModifiersBuilders.Modifiers modifiers)` Sets the modifiers of text. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder#setMultilineAlignment(int)(int multilineAlignment)` Sets the multiline alignment for text within bounds of the Text element. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder#setOverflow(int)(int overflow)` Sets the overflow for text. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder#setScalable(boolean)(boolean isScalable)` Sets whether the text size will change if user has changed the default font size. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder#setTypography(int)(int typography)` Sets the typography for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Text`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder#setUnderline(boolean)(boolean underline)` Sets the text to be underlined. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder#setWeight(int)(int 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(@NonNull Context context, @NonNull String text)
```

Creates a builder for a `https://developer.android.com/reference/androidx/wear/protolayout/material/Text` component with static text.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | The application's context. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html text` | The text content for this component. |

### Builder

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

```
public Builder(
    @NonNull Context context,
    @NonNull TypeBuilders.StringProp text,
    @NonNull TypeBuilders.StringLayoutConstraint stringLayoutConstraint
)
```

Creates a builder for a `https://developer.android.com/reference/androidx/wear/protolayout/material/Text`.

While this component 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).

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | The application's context. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/TypeBuilders.StringProp text` | The text content for this component. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/TypeBuilders.StringLayoutConstraint stringLayoutConstraint` | Layout constraints used to correctly measure Text view size and align text when `text` has dynamic value. |

## Public methods

### build

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

```
public @NonNull Text build()
```

Constructs and returns `https://developer.android.com/reference/androidx/wear/protolayout/material/Text` with the provided content and look.

### setColor

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

```
public @NonNull Text.Builder setColor(@NonNull ColorBuilders.ColorProp color)
```

Sets the color for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Text`. If not set, onPrimary color from the `https://developer.android.com/reference/androidx/wear/protolayout/material/Colors#DEFAULT()` will be used.

### setItalic

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

```
public @NonNull Text.Builder setItalic(boolean italic)
```

Sets the text to be italic. If not set, false will be used.

### setMaxLines

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

```
public @NonNull Text.Builder setMaxLines(@IntRange(from = 1) int maxLines)
```

Sets the maximum lines of text. If not set, 1 will be used.

### setModifiers

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

```
public @NonNull Text.Builder setModifiers(@NonNull ModifiersBuilders.Modifiers modifiers)
```

Sets the modifiers of text.

### setMultilineAlignment

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

```
public @NonNull Text.Builder setMultilineAlignment(int multilineAlignment)
```

Sets the multiline alignment for text within bounds of the Text element. Note that this option has no effect for single line of text, and for that, alignment on the outer container should be used. If not set, `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders#TEXT_ALIGN_CENTER()` will be used.

### setOverflow

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

```
public @NonNull Text.Builder setOverflow(int overflow)
```

Sets the overflow for text. If not set, `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders#TEXT_OVERFLOW_ELLIPSIZE_END()` will be used.

### setScalable

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

```
public @NonNull Text.Builder setScalable(boolean isScalable)
```

Sets whether the text size will change if user has changed the default font size. If not set, true will be used.

### setTypography

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

```
public @NonNull Text.Builder setTypography(int typography)
```

Sets the typography for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Text`. If not set, `https://developer.android.com/reference/androidx/wear/protolayout/material/Typography#TYPOGRAPHY_DISPLAY1()` will be used.

### setUnderline

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

```
public @NonNull Text.Builder setUnderline(boolean underline)
```

Sets the text to be underlined. If not set, false will be used.

### setWeight

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

```
public @NonNull Text.Builder setWeight(int weight)
```

Sets the weight of the font. If not set, default weight for the chosen Typography will be used.