# Text.Builder

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/wear/protolayout/material/Text.Builder "View this page in Java")

<br />

```
class Text.Builder
```

<br />

*** ** * ** ***

Builder class for[Text](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text).

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                            ### Public constructors                                                                                                                                                                                                                                                                                                                                                                                             |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text.Builder#Builder(android.content.Context,java.lang.String))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, text: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Creates a builder for a[Text](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text)component with static text.                                                                                                                                                                                                                                                                                                          |
| [Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text.Builder#Builder(android.content.Context,androidx.wear.protolayout.TypeBuilders.StringProp,androidx.wear.protolayout.TypeBuilders.StringLayoutConstraint))`(` ` context: `[Context](https://developer.android.com/reference/android/content/Context.html)`,` ` text: `[TypeBuilders.StringProp](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/TypeBuilders.StringProp)`,` ` stringLayoutConstraint: `[TypeBuilders.StringLayoutConstraint](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/TypeBuilders.StringLayoutConstraint) `)` Creates a builder for a[Text](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text). |

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

Creates a builder for a[Text](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text)component with static text.  

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|--------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html) | The application's context.           |
| `text: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)  | The text content for this component. |

### Builder

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

```
Builder(
    context: Context,
    text: TypeBuilders.StringProp,
    stringLayoutConstraint: TypeBuilders.StringLayoutConstraint
)
```

Creates a builder for a[Text](https://developer.android.com/reference/kotlin/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                                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)                                                                                    | The application's context.                                                                              |
| `text: `[TypeBuilders.StringProp](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/TypeBuilders.StringProp)                                           | The text content for this component.                                                                    |
| `stringLayoutConstraint: `[TypeBuilders.StringLayoutConstraint](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/TypeBuilders.StringLayoutConstraint) | Layout constraints used to correctly measure Text view size and align text when`text`has dynamic value. |

## Public functions

### build

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

```
fun build(): Text
```

Constructs and returns[Text](https://developer.android.com/reference/kotlin/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)  

```
fun setColor(color: ColorBuilders.ColorProp): Text.Builder
```

Sets the color for the[Text](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text). If not set, onPrimary color from the[DEFAULT](https://developer.android.com/reference/kotlin/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)  

```
fun setItalic(italic: Boolean): Text.Builder
```

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)  

```
fun setMaxLines(maxLines: @IntRange(from = 1) Int): Text.Builder
```

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)  

```
fun setModifiers(modifiers: ModifiersBuilders.Modifiers): Text.Builder
```

Sets the modifiers of text.  

### setMultilineAlignment

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

```
fun setMultilineAlignment(multilineAlignment: Int): Text.Builder
```

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,[TEXT_ALIGN_CENTER](https://developer.android.com/reference/kotlin/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)  

```
fun setOverflow(overflow: Int): Text.Builder
```

Sets the overflow for text. If not set,[TEXT_OVERFLOW_ELLIPSIZE_END](https://developer.android.com/reference/kotlin/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)  

```
fun setScalable(isScalable: Boolean): Text.Builder
```

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)  

```
fun setTypography(typography: Int): Text.Builder
```

Sets the typography for the[Text](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text). If not set,[TYPOGRAPHY_DISPLAY1](https://developer.android.com/reference/kotlin/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)  

```
fun setUnderline(underline: Boolean): Text.Builder
```

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)  

```
fun setWeight(weight: Int): Text.Builder
```

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