# Text

# Text

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)  
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 "View this page in Java")


```
class Text : LayoutElementBuilders.LayoutElement
```

<br />

*** ** * ** ***

ProtoLayout component [Text](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text) that represents text object holding any information.

There are pre-built typography styles that can be obtained from constants in [FontStyle](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle).

When accessing the contents of a container for testing, note that this element can't be simply casted back to the original type, i.e.:  

```kotlin
Text text = new Text...
Box box = new Box.Builder().addContent(text).build();

Text myText = (Text) box.getContents().get(0);
```
will fail.

To be able to get [Text](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text) object from any layout element, [fromLayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text#fromLayoutElement(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement)) method should be used, i.e.:  

```kotlin
Text myText = Text.fromLayoutElement(box.getContents().get(0));
```

## Summary

|                                                                                                             ### Nested types                                                                                                             |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `class `[Text.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text.Builder) Builder class for [Text](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text). |

|                                                            ### Public functions                                                             |
|---------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Text](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text)`?`                             | [fromLayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text#fromLayoutElement(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))`(element: `[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`)` Returns Material Text object from the given LayoutElement (e.g. one retrieved from a container's content with `container.getContents().get(index)`) if that element can be converted to Material Text. |
| [ColorBuilders.ColorProp](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ColorBuilders.ColorProp)                 | [getColor](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text#getColor())`()` Returns the color of this Text element.                                                                                                                                                                                                                                                                                                                                                                                                             |
| [LayoutElementBuilders.FontStyle](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.FontStyle) | [getFontStyle](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text#getFontStyle())`()` Returns the font style of this Text element.                                                                                                                                                                                                                                                                                                                                                                                                |
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)                                                             | [getLineHeight](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text#getLineHeight())`()` Returns the line height of this Text element.                                                                                                                                                                                                                                                                                                                                                                                             |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                 | [getMaxLines](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text#getMaxLines())`()` Returns the max lines of text of this Text element.                                                                                                                                                                                                                                                                                                                                                                                           |
| [ModifiersBuilders.Modifiers](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ModifiersBuilders.Modifiers)         | [getModifiers](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text#getModifiers())`()` Returns the modifiers of this Text element.                                                                                                                                                                                                                                                                                                                                                                                                 |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                 | [getMultilineAlignment](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text#getMultilineAlignment())`()` Returns the multiline alignment of this Text element.                                                                                                                                                                                                                                                                                                                                                                     |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                 | [getOverflow](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text#getOverflow())`()` Returns the overflow of this Text element.                                                                                                                                                                                                                                                                                                                                                                                                    |
| [TypeBuilders.StringProp](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/TypeBuilders.StringProp)                 | [getText](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text#getText())`()` Returns the text of this Text element.                                                                                                                                                                                                                                                                                                                                                                                                                |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                 | [getWeight](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text#getWeight())`()` Returns the overflow of this Text element.                                                                                                                                                                                                                                                                                                                                                                                                        |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                         | [isItalic](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text#isItalic())`()` Returns whether the Text is in italic.                                                                                                                                                                                                                                                                                                                                                                                                              |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                         | [isUnderline](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Text#isUnderline())`()` Returns whether the Text is underlined.                                                                                                                                                                                                                                                                                                                                                                                                       |

## Public functions

### fromLayoutElement

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

```
java-static fun fromLayoutElement(element: LayoutElementBuilders.LayoutElement): Text?
```

Returns Material Text object from the given LayoutElement (e.g. one retrieved from a container's content with `container.getContents().get(index)`) if that element can be converted to Material Text. Otherwise, it will return null.  

### getColor

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

```
fun getColor(): ColorBuilders.ColorProp
```

Returns the color of this Text element.  

### getFontStyle

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

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

Returns the font style of this Text element.  

### getLineHeight

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

```
fun getLineHeight(): Float
```

Returns the line height of this Text element.  

### getMaxLines

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

```
fun getMaxLines(): Int
```

Returns the max lines of text of this Text element.  

### getModifiers

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

```
fun getModifiers(): ModifiersBuilders.Modifiers
```

Returns the modifiers of this Text element.  

### getMultilineAlignment

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

```
fun getMultilineAlignment(): Int
```

Returns the multiline alignment of this Text element.  

### getOverflow

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

```
fun getOverflow(): Int
```

Returns the overflow of this Text element.  

### getText

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

```
fun getText(): TypeBuilders.StringProp
```

Returns the text of this Text element.  

### getWeight

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

```
fun getWeight(): Int
```

Returns the overflow of this Text element.  

### isItalic

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

```
fun isItalic(): Boolean
```

Returns whether the Text is in italic.  

### isUnderline

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

```
fun isUnderline(): Boolean
```

Returns whether the Text is underlined.