# TextKt

Added in 1.3.0

*** ** * ** ***


```
public final class TextKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement` | `https://developer.android.com/reference/androidx/wear/protolayout/material3/TextKt#(androidx.wear.protolayout.material3.MaterialScope).text(androidx.wear.protolayout.types.LayoutString,androidx.wear.protolayout.modifiers.LayoutModifier,kotlin.Int,androidx.wear.protolayout.types.LayoutColor,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.collections.List,kotlin.collections.List)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/material3/MaterialScope receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/types/LayoutString text, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/modifiers/LayoutModifier modifier, int typography, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/types/LayoutColor color, boolean italic, boolean underline, boolean scalable, int maxLines, int alignment, int overflow, @https://developer.android.com/reference/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 400) @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.FontSetting> settings, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Float.html> incrementsForTypographySize )` ProtoLayout component that represents text object holding any information. |

## Public methods

### text

Artifact: [androidx.wear.protolayout:protolayout-material3](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/material3/Text.kt+function:text)

```
public static final @NonNull LayoutElementBuilders.LayoutElement text(
    @NonNull MaterialScope receiver,
    @NonNull LayoutString text,
    @NonNull LayoutModifier modifier,
    int typography,
    @NonNull LayoutColor color,
    boolean italic,
    boolean underline,
    boolean scalable,
    int maxLines,
    int alignment,
    int overflow,
    @RequiresSchemaVersion(major = 1, minor = 400) @NonNull List<@NonNull LayoutElementBuilders.FontSetting> settings,
    @NonNull List<@NonNull Float> incrementsForTypographySize
)
```

ProtoLayout component that represents text object holding any information.

There are pre-defined typography styles that can be obtained from Materials token system in `https://developer.android.com/reference/androidx/wear/protolayout/material3/Typography`.

This text, when added to the `titleSlot`, `bottomSlot` and `labelForBottomSlot` in `https://developer.android.com/reference/androidx/wear/protolayout/material3/package-summary#(androidx.wear.protolayout.material3.MaterialScope).primaryLayout(kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function1,androidx.wear.protolayout.ModifiersBuilders.Clickable,androidx.wear.protolayout.material3.PrimaryLayoutMargins)`, is considered as important for accessibility automatically and gets read out by the screen reader even without content description provided in the `https://developer.android.com/reference/androidx/wear/protolayout/material3/package-summary#(androidx.wear.protolayout.material3.MaterialScope).text(androidx.wear.protolayout.types.LayoutString,androidx.wear.protolayout.modifiers.LayoutModifier,kotlin.Int,androidx.wear.protolayout.types.LayoutColor,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.collections.List,kotlin.collections.List)`. This behavior can be removed with LayoutModifier.clearSemantics if not desired. In all other places, this text is considered as not important for accessibility by default unless content description is specifically provided in the `https://developer.android.com/reference/androidx/wear/protolayout/material3/package-summary#(androidx.wear.protolayout.material3.MaterialScope).text(androidx.wear.protolayout.types.LayoutString,androidx.wear.protolayout.modifiers.LayoutModifier,kotlin.Int,androidx.wear.protolayout.types.LayoutColor,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.collections.List,kotlin.collections.List)`.

```kotlin
import androidx.wear.protolayout.material3.Typography
import androidx.wear.protolayout.material3.materialScope
import androidx.wear.protolayout.material3.text
import androidx.wear.protolayout.types.layoutString

materialScope(context, deviceConfiguration) {
        text(text = "Hello Material3".layoutString, typography = Typography.DISPLAY_LARGE)
    }
```

```kotlin
import androidx.wear.protolayout.expression.DynamicBuilders.DynamicString
import androidx.wear.protolayout.material3.Typography
import androidx.wear.protolayout.material3.materialScope
import androidx.wear.protolayout.material3.text
import androidx.wear.protolayout.types.LayoutString
import androidx.wear.protolayout.types.asLayoutConstraint

materialScope(context, deviceConfiguration) {
        this.text(
            text =
                LayoutString(
                    "Static",
                    DynamicString.constant("Dynamic"),
                    "LongestConstraint".asLayoutConstraint(),
                ),
            typography = Typography.DISPLAY_LARGE,
            color = colorScheme.tertiary,
            underline = true,
            maxLines = 5,
        )
    }
```

```kotlin
import androidx.wear.protolayout.material3.Typography
import androidx.wear.protolayout.material3.materialScope
import androidx.wear.protolayout.material3.text
import androidx.wear.protolayout.types.layoutString

materialScope(context, deviceConfiguration) {
        text(
            text = "Hello Material3".layoutString,
            typography = Typography.DISPLAY_LARGE,
            incrementsForTypographySize = listOf(-4f, -2f, 2f),
        )
    }
```

```kotlin
import androidx.wear.protolayout.material3.materialScope
import androidx.wear.protolayout.material3.primaryLayout
import androidx.wear.protolayout.material3.text
import androidx.wear.protolayout.modifiers.LayoutModifier
import androidx.wear.protolayout.modifiers.clearSemantics
import androidx.wear.protolayout.types.layoutString

materialScope(context, deviceConfiguration) {
        primaryLayout(
            titleSlot = {
                text("App title".layoutString, modifier = LayoutModifier.clearSemantics())
            },
            mainSlot = { text("Main content".layoutString) },
            bottomSlot = {
                text("Bottom slot".layoutString, modifier = LayoutModifier.clearSemantics())
            },
            labelForBottomSlot = {
                text("Bottom label".layoutString, modifier = LayoutModifier.clearSemantics())
            },
        )
    }
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/types/LayoutString text` | The text content for this component. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/modifiers/LayoutModifier modifier` | Modifiers to set to this element. |
| `int typography` | The typography from `https://developer.android.com/reference/androidx/wear/protolayout/material3/Typography` to be applied to this text. This will have predefined default value specified by each components that uses this text, to achieve the recommended look. If using some of `Typography.NUMERAL_` styles and the provided text is animating, the `https://developer.android.com/reference/androidx/wear/protolayout/material3/package-summary#(androidx.wear.protolayout.material3.MaterialScope).text(androidx.wear.protolayout.types.LayoutString,androidx.wear.protolayout.modifiers.LayoutModifier,kotlin.Int,androidx.wear.protolayout.types.LayoutColor,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.collections.List,kotlin.collections.List)` should include `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.FontSetting#tabularNum()` font feature setting for the best results and to avoid text changing its width based on the number present. Value is one of the following: - `2` - `3` - `4` - `5` - `6` - `7` - `8` - `9` - `10` - `11` - `12` - `13` - `14` - `15` - `16` - `17` - `18` - `19` <br /> |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/types/LayoutColor color` | The color to be applied to this text. It is recommended to use predefined default styles created by each component or `getColorProp(token)`. |
| `boolean italic` | Whether text should be displayed as italic. |
| `boolean underline` | Whether text should be displayed as underlined. |
| `boolean scalable` | Whether text should scale with the user font size. |
| `int maxLines` | The maximum number of lines that text can occupy. |
| `int alignment` | The horizontal alignment of the multiple lines of text or one line of text when text overflows. |
| `int overflow` | The overflow strategy when text doesn't have enough space to be shown. |
| `@https://developer.android.com/reference/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 400) @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.FontSetting> settings` | The collection of font settings to be applied. If more than one Setting with the same axis tag is specified, the first one will be used. Supported settings depend on the font used and renderer version. Each default typography will apply appropriate default setting axes for it (`https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.FontSetting#weight(int)`, `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.FontSetting#width(float)` and `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.FontSetting#roundness(int)`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Float.html> incrementsForTypographySize` | The collection increments for the given `https://developer.android.com/reference/androidx/wear/protolayout/material3/package-summary#(androidx.wear.protolayout.material3.MaterialScope).text(androidx.wear.protolayout.types.LayoutString,androidx.wear.protolayout.modifiers.LayoutModifier,kotlin.Int,androidx.wear.protolayout.types.LayoutColor,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.collections.List,kotlin.collections.List)` size to allow text to grow or shrink for that amount to make text auto size in the space it has. The largest increment that fits the most text will be used. Increments can be positive for text to grow more than the specified `https://developer.android.com/reference/androidx/wear/protolayout/material3/package-summary#(androidx.wear.protolayout.material3.MaterialScope).text(androidx.wear.protolayout.types.LayoutString,androidx.wear.protolayout.modifiers.LayoutModifier,kotlin.Int,androidx.wear.protolayout.types.LayoutColor,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.collections.List,kotlin.collections.List)` or negative, for text to be smaller than the specified `https://developer.android.com/reference/androidx/wear/protolayout/material3/package-summary#(androidx.wear.protolayout.material3.MaterialScope).text(androidx.wear.protolayout.types.LayoutString,androidx.wear.protolayout.modifiers.LayoutModifier,kotlin.Int,androidx.wear.protolayout.types.LayoutColor,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.collections.List,kotlin.collections.List)`. All other parameters of the `https://developer.android.com/reference/androidx/wear/protolayout/material3/Typography` stay as defined by the `https://developer.android.com/reference/androidx/wear/protolayout/material3/package-summary#(androidx.wear.protolayout.material3.MaterialScope).text(androidx.wear.protolayout.types.LayoutString,androidx.wear.protolayout.modifiers.LayoutModifier,kotlin.Int,androidx.wear.protolayout.types.LayoutColor,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.collections.List,kotlin.collections.List)` parameter. For the best results when using auto size, `https://developer.android.com/reference/androidx/wear/protolayout/material3/package-summary#(androidx.wear.protolayout.material3.MaterialScope).text(androidx.wear.protolayout.types.LayoutString,androidx.wear.protolayout.modifiers.LayoutModifier,kotlin.Int,androidx.wear.protolayout.types.LayoutColor,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.collections.List,kotlin.collections.List)` should be negative, to allow text to shrink while still maintaining space between multiple lines. If using positive increments in `https://developer.android.com/reference/androidx/wear/protolayout/material3/package-summary#(androidx.wear.protolayout.material3.MaterialScope).text(androidx.wear.protolayout.types.LayoutString,androidx.wear.protolayout.modifiers.LayoutModifier,kotlin.Int,androidx.wear.protolayout.types.LayoutColor,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.collections.List,kotlin.collections.List)` to make the text bigger, pay attention to the line height as that one won't be increased and if increment is too big, text in multiple lines can start overlapping. Positive increments on a single line text can work correctly. Note that this text element should be used in a constraint parent, not purely the one with `wrap` dimension for the best results. |