Google is committed to advancing racial equity for Black communities. See how.

TextFieldValue

@Immutable data class TextFieldValue
kotlin.Any
   ↳ androidx.compose.ui.text.input.TextFieldValue

A class holding information about the editing state.

The input service updates text selection, cursor, text and text composition. This class represents those values and it is possible to observe changes to those values in the text editing composables.

Input service composition is an instance of text produced by IME. An example visual for the composition is that the currently composed word is visually separated from others with underline, or text background. For description of composition please check W3C IME Composition

This class stores a snapshot of the input state of the edit buffer and provide utility functions for answering IME requests such as getTextBeforeCursor, getSelectedText.

Summary

Public constructors
<init>(text: String = "", selection: TextRange = TextRange.Zero, composition: TextRange? = null)

A class holding information about the editing state.

Extension functions
From androidx.compose.ui.text.input
String

Helper function for getting text currently selected.

String

Helper function for getting text after selection range.

String

Helper function for getting text before selection range.

Properties
TextRange?

A composition range visible to IME.

TextRange

the selection range.

String

the text will be rendered

Companion properties
Saver<TextFieldValue, Any>

The default Saver implementation for TextFieldValue.

Public constructors

<init>

TextFieldValue(
    text: String = "",
    selection: TextRange = TextRange.Zero,
    composition: TextRange? = null)

A class holding information about the editing state.

The input service updates text selection, cursor, text and text composition. This class represents those values and it is possible to observe changes to those values in the text editing composables.

Input service composition is an instance of text produced by IME. An example visual for the composition is that the currently composed word is visually separated from others with underline, or text background. For description of composition please check W3C IME Composition

This class stores a snapshot of the input state of the edit buffer and provide utility functions for answering IME requests such as getTextBeforeCursor, getSelectedText.

Parameters
text: String = "" the text will be rendered
selection: TextRange = TextRange.Zero the selection range. If the selection is collapsed, it represents cursor location. Selection range must be within the bounds of the text, otherwise an exception will be thrown.
composition: TextRange? = null A composition range visible to IME. If null, there is no composition range. Composition range must be within the bounds of the text, otherwise an exception will be thrown. For description of composition please check W3C IME Composition(https://www.w3

Properties

composition

@Stable val composition: TextRange?

A composition range visible to IME. If null, there is no composition range. Composition range must be within the bounds of the text, otherwise an exception will be thrown. For description of composition please check W3C IME Composition(https://www.w3

  • .org/TR/ime-api/#ime-composition).

selection

@Stable val selection: TextRange

the selection range. If the selection is collapsed, it represents cursor location. Selection range must be within the bounds of the text, otherwise an exception will be thrown.

text

@Stable val text: String

the text will be rendered

Companion properties

Saver

val Saver: Saver<TextFieldValue, Any>

The default Saver implementation for TextFieldValue.