# TextKt

Added in 1.3.0

*** ** * ** ***

<br />

```
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.Text` | `https://developer.android.com/reference/androidx/wear/protolayout/layout/TextKt#basicText(androidx.wear.protolayout.types.LayoutString,androidx.wear.protolayout.LayoutElementBuilders.FontStyle,androidx.wear.protolayout.modifiers.LayoutModifier,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Float)( @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/wear/protolayout/LayoutElementBuilders.FontStyle fontStyle, https://developer.android.com/reference/androidx/wear/protolayout/modifiers/LayoutModifier modifier, int maxLines, int alignment, int overflow, @https://developer.android.com/reference/androidx/annotation/Dimension(unit = 2) float lineHeight )` Builds a text string. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.FontStyle` | `https://developer.android.com/reference/androidx/wear/protolayout/layout/TextKt#fontStyle(kotlin.Float,kotlin.Boolean,kotlin.Boolean,androidx.wear.protolayout.types.LayoutColor,kotlin.Int,kotlin.Float,kotlin.collections.List,kotlin.collections.List,kotlin.collections.List)( @https://developer.android.com/reference/androidx/annotation/Dimension(unit = 2) float size, boolean italic, boolean underline, https://developer.android.com/reference/androidx/wear/protolayout/types/LayoutColor color, int weight, float letterSpacingEm, @https://developer.android.com/reference/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 300) @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> additionalSizesSp, @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/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/java/lang/String.html> preferredFontFamilies )` Builds the styling of a font (e.g. font size, and metrics). |

## Public methods

### basicText

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/layout/Text.kt+function:basicText) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.3.0)

```
public static final @NonNull LayoutElementBuilders.Text basicText(
    @NonNull LayoutString text,
    LayoutElementBuilders.FontStyle fontStyle,
    LayoutModifier modifier,
    int maxLines,
    int alignment,
    int overflow,
    @Dimension(unit = 2) float lineHeight
)
```

Builds a text string.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/types/LayoutString text` | The text to render. |
| `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.FontStyle fontStyle` | The style of font to use (size, bold etc). If not specified, defaults to the platform's default body font. |
| `https://developer.android.com/reference/androidx/wear/protolayout/modifiers/LayoutModifier modifier` | Modifiers to set to this element. |
| `int maxLines` | The maximum number of lines that can be represented by the `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.Text` element. If not defined, the `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.Text` element will be treated as a single-line element. |
| `int alignment` | Alignment of the text within its bounds. Note that a `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.Text` element will size itself to wrap its contents, so this option is meaningless for single-line text (for that, use alignment of the outer container), unless this text overflows. For multi-line text, however, this will set the alignment of lines relative to the `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.Text` element bounds. If not defined, defaults to TEXT_ALIGN_CENTER. |
| `int overflow` | How to handle text which overflows the bound of the `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.Text` element. A `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.Text` element will grow as large as possible inside its parent container (while still respecting max_lines); if it cannot grow large enough to render all of its text, the text which cannot fit inside its container will be truncated. If not defined, defaults to TEXT_OVERFLOW_TRUNCATE. |
| `@https://developer.android.com/reference/androidx/annotation/Dimension(unit = 2) float lineHeight` | The explicit height between lines of text. This is equivalent to the vertical distance between subsequent baselines. If not specified, defaults the font's recommended interline spacing. |

### fontStyle

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/layout/Text.kt+function:fontStyle)

```
public static final @NonNull LayoutElementBuilders.FontStyle fontStyle(
    @Dimension(unit = 2) float size,
    boolean italic,
    boolean underline,
    LayoutColor color,
    int weight,
    float letterSpacingEm,
    @RequiresSchemaVersion(major = 1, minor = 300) @NonNull List<@NonNull Float> additionalSizesSp,
    @RequiresSchemaVersion(major = 1, minor = 400) @NonNull List<@NonNull LayoutElementBuilders.FontSetting> settings,
    @RequiresSchemaVersion(major = 1, minor = 400) @NonNull List<@NonNull String> preferredFontFamilies
)
```

Builds the styling of a font (e.g. font size, and metrics).

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Dimension(unit = 2) float size` | The size of the font, in scaled pixels (sp). If not specified, defaults to the size of the system's "body" font. |
| `boolean italic` | Whether the text should be rendered in a italic typeface. |
| `boolean underline` | Whether the text should be rendered with an underline. |
| `https://developer.android.com/reference/androidx/wear/protolayout/types/LayoutColor color` | The text color. If not defined, defaults to white. |
| `int weight` | 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". |
| `float letterSpacingEm` | The text letter-spacing. Positive numbers increase the space between letters while negative numbers tighten the space. If not specified, defaults to 0. |
| `@https://developer.android.com/reference/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 300) @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> additionalSizesSp` | when 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. |
| `@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 by the system and the renderer version. However, if using `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.FontSetting#weight(int)` axis with a value higher than `500`, consider adding a fallback `https://developer.android.com/reference/androidx/wear/protolayout/layout/package-summary#fontStyle(kotlin.Float,kotlin.Boolean,kotlin.Boolean,androidx.wear.protolayout.types.LayoutColor,kotlin.Int,kotlin.Float,kotlin.collections.List,kotlin.collections.List,kotlin.collections.List)` parameter as `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders#FONT_WEIGHT_MEDIUM()` or `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders#FONT_WEIGHT_BOLD()` to avoid text looking too thin on fonts that don't support weight axis. |
| `@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/java/lang/String.html> preferredFontFamilies` | is the ordered list of font families to pick from for this `https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.FontStyle`. 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. Note that support for font family customization is dependent on the target platform. |