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

androidx.ui.text

Interfaces

Paragraph

A paragraph of text that is laid out.

ParagraphIntrinsics

Calculates and presents the intrinsic width and height of text.

Typeface

A class that can be used for changing the font used in text.

Classes

AnnotatedString

The basic data structure of text with multiple styles.

InlineTextContent

A data class that stores a composable to be inserted into the text layout.

MultiParagraph

Lays out and renders multiple paragraphs at once.

MultiParagraphIntrinsics

Calculates and provides the intrinsic width and height of text that contains ParagraphStyle.

ParagraphConstraints

Layout constraints for Paragraph objects.

ParagraphStyle

Paragraph styling configuration for a paragraph.

Placeholder

A placeholder is a rectangle box inserted into text, which tells the text processor to leave an empty space.

SoftwareKeyboardController

Provide software keyboard control.

SpanStyle

Styling configuration for a text span.

TextLayoutInput

The data class which holds the set of parameters of the text layout computation.

TextLayoutResult

The data class which holds text layout result.

TextRange

An immutable text range class, represents a text range from start (inclusive) to end (exclusive).

TextStyle

Styling configuration for a Text.

Type-aliases

ParagraphStyleRange

The class changes the paragraph level style of the specified range.

SpanStyleRange

The class changes the character level style of the specified range.

StringAnnotation

The class that stores a string type annotation.

Annotations

InternalTextApi

Enums

PlaceholderVerticalAlign

The settings used to specify how a placeholder is vertically aligned within a text line.

Top-level functions summary

AnnotatedString
AnnotatedString(text: String, spanStyle: SpanStyle, paragraphStyle: ParagraphStyle? = null)

Create an AnnotatedString with a spanStyle that will apply to the whole text.

AnnotatedString
AnnotatedString(text: String, paragraphStyle: ParagraphStyle)

Create an AnnotatedString with a paragraphStyle that will apply to the whole text.

AnnotatedString

Build a new AnnotatedString by populating newly created AnnotatedString.Builder provided by builder.

Unit
CoreText(text: AnnotatedString, modifier: Modifier = Modifier, style: TextStyle, softWrap: Boolean, overflow: TextOverflow, maxLines: Int, inlineContent: Map<String, InlineTextContent>, onTextLayout: (TextLayoutResult) -> Unit)

CoreText is a low level element that displays text with multiple different styles.

Unit
CoreTextField(value: EditorValue, modifier: Modifier, onValueChange: (EditorValue) -> Unit, textStyle: TextStyle = TextStyle.Default, keyboardType: KeyboardType = KeyboardType.Text, imeAction: ImeAction = ImeAction.Unspecified, onFocusChange: (Boolean) -> Unit = {}, onImeActionPerformed: (ImeAction) -> Unit = {}, visualTransformation: VisualTransformation = VisualTransformation.None, onTextLayout: (TextLayoutResult) -> Unit = {}, onTextInputStarted: (SoftwareKeyboardController) -> Unit = {})

Unit
CoreTextField(value: TextFieldValue, modifier: Modifier = Modifier, onValueChange: (TextFieldValue) -> Unit, textStyle: TextStyle = TextStyle.Default, keyboardType: KeyboardType = KeyboardType.Text, imeAction: ImeAction = ImeAction.Unspecified, onImeActionPerformed: (ImeAction) -> Unit = {}, onFocusChanged: (Boolean) -> Unit = {}, visualTransformation: VisualTransformation = VisualTransformation.None, onTextLayout: (TextLayoutResult) -> Unit = {}, onTextInputStarted: (SoftwareKeyboardController) -> Unit = {})

Base composable that enables users to edit text via hardware or software keyboard.

Paragraph
Paragraph(text: String, style: TextStyle, spanStyles: List<AnnotatedString.Range<SpanStyle>> = listOf(), placeholders: List<AnnotatedString.Range<Placeholder>> = listOf(), maxLines: Int = DefaultMaxLines, ellipsis: Boolean = false, constraints: ParagraphConstraints, density: Density, resourceLoader: Font.ResourceLoader)

Lays out a given text with the given constraints.

Paragraph
Paragraph(paragraphIntrinsics: ParagraphIntrinsics, maxLines: Int = DefaultMaxLines, ellipsis: Boolean = false, constraints: ParagraphConstraints)

Lays out the text in ParagraphIntrinsics with the given constraints.

ParagraphIntrinsics
ParagraphIntrinsics(text: String, style: TextStyle, spanStyles: List<AnnotatedString.Range<SpanStyle>> = listOf(), placeholders: List<AnnotatedString.Range<Placeholder>> = listOf(), density: Density, resourceLoader: Font.ResourceLoader)

Factory method to create a ParagraphIntrinsics.

TextRange
TextRange(index: Int)

Creates a TextRange where start is equal to end, and the value of those are index.

AnnotatedString

Build a new AnnotatedString by populating newly created AnnotatedString.Builder provided by builder.

ParagraphStyle
lerp(start: ParagraphStyle, stop: ParagraphStyle, fraction: Float)

Interpolate between two ParagraphStyles.

SpanStyle
lerp(start: SpanStyle, stop: SpanStyle, fraction: Float)

Interpolate between two span styles.

TextStyle
lerp(start: TextStyle, stop: TextStyle, fraction: Float)

Interpolate between two text styles.

TextStyle

Fills missing values in TextStyle with default values and resolve TextDirection.

Top-level properties summary

HorizontalAlignmentLine

AlignmentLine defined by the baseline of a first line of a CoreText.

HorizontalAlignmentLine

AlignmentLine defined by the baseline of the last line of a CoreText.

Extension functions summary

For kotlin.CharSequence
String

For kotlin.String
String

Returns capitalized String.

String

Returns capitalized String.

String

Returns decapitalized String.

String

Returns decapitalized String.

String

Returns lowercase transformed String.

String

Returns lowercase transformed String.

String

Returns uppercase transformed String.

String

Returns uppercase transformed String.

For Builder
Unit
AnnotatedString.Builder.appendInlineContent(id: String, alternateText: String = REPLACEMENT_CHAR)

Append an inline content into the AnnotatedString.

R
AnnotatedString.Builder.withStyle(style: SpanStyle, crossinline block: AnnotatedString.Builder.() -> R)

Pushes style to the AnnotatedString.Builder, executes block and then pops the style.

R

Pushes style to the AnnotatedString.Builder, executes block and then pops the style.

For AnnotatedString
AnnotatedString
AnnotatedString.capitalize(localeList: LocaleList = LocaleList.current)

Create capitalized AnnotatedString

AnnotatedString
AnnotatedString.decapitalize(localeList: LocaleList = LocaleList.current)

Create capitalized AnnotatedString

AnnotatedString

Return a substring for the AnnotatedString and include the styles in the range of start (inclusive) and end (exclusive).

AnnotatedString
AnnotatedString.toLowerCase(localeList: LocaleList = LocaleList.current)

Create lower case transformed AnnotatedString

AnnotatedString
AnnotatedString.toUpperCase(localeList: LocaleList = LocaleList.current)

Create upper case transformed AnnotatedString

For SemanticsPropertyReceiver
Unit

Whether the component supports input methods.

Extension properties summary

For SemanticsPropertyReceiver
ImeAction

Contains the IME action provided by the node.

For AnnotatedString
Int

Returns the length of the AnnotatedString.

Top-level functions

AnnotatedString

fun AnnotatedString(
    text: String,
    spanStyle: SpanStyle,
    paragraphStyle: ParagraphStyle? = null
): AnnotatedString

Create an AnnotatedString with a spanStyle that will apply to the whole text.

Parameters
spanStyle: SpanStyle SpanStyle to be applied to whole text
paragraphStyle: ParagraphStyle? = null ParagraphStyle to be applied to whole text

AnnotatedString

fun AnnotatedString(
    text: String,
    paragraphStyle: ParagraphStyle
): AnnotatedString

Create an AnnotatedString with a paragraphStyle that will apply to the whole text.

Parameters
paragraphStyle: ParagraphStyle ParagraphStyle to be applied to whole text

AnnotatedString

inline fun AnnotatedString(builder: AnnotatedString.Builder.() -> Unit): AnnotatedString

Deprecated.

Build a new AnnotatedString by populating newly created AnnotatedString.Builder provided by builder.

import androidx.ui.text.SpanStyle
import androidx.ui.text.annotatedString
import androidx.ui.text.withStyle

// create an AnnotatedString using the lambda builder
annotatedString {
    // append "Hello" with red text color
    withStyle(SpanStyle(color = Color.Red)) {
        append("Hello")
    }
    append(" ")
    // append "Hello" with blue text color
    withStyle(SpanStyle(color = Color.Blue)) {
        append("World!")
    }
}
Parameters
builder: AnnotatedString.Builder.() -> Unit lambda to modify AnnotatedString.Builder

CoreText

@Composable fun CoreText(
    text: AnnotatedString,
    modifier: Modifier = Modifier,
    style: TextStyle,
    softWrap: Boolean,
    overflow: TextOverflow,
    maxLines: Int,
    inlineContent: Map<String, InlineTextContent>,
    onTextLayout: (TextLayoutResult) -> Unit
): Unit

CoreText is a low level element that displays text with multiple different styles. The text to display is described using a AnnotatedString. Typically you will instead want to use androidx.ui.foundation.Text, which is a higher level Text element that contains semantics and consumes style information from a theme.

Parameters
text: AnnotatedString AnnotatedString encoding a styled text.
modifier: Modifier = Modifier Modifier to apply to this layout node.
style: TextStyle Style configuration for the text such as color, font, line height etc.
softWrap: Boolean Whether the text should break at soft line breaks. If false, the glyphs in the text will be positioned as if there was unlimited horizontal space. If softWrap is false, overflow and TextAlign may have unexpected effects.
overflow: TextOverflow How visual overflow should be handled.
maxLines: Int An optional maximum number of lines for the text to span, wrapping if necessary. If the text exceeds the given number of lines, it will be truncated according to overflow and softWrap. If it is not null, then it must be greater than zero.
inlineContent: Map<String, InlineTextContent> A map store composables that replaces certain ranges of the text. It's used to insert composables into text layout. Check InlineTextContent for more information.
onTextLayout: (TextLayoutResult) -> Unit Callback that is executed when a new text layout is calculated.

CoreTextField

@Composable fun CoreTextField(
    value: EditorValue,
    modifier: Modifier,
    onValueChange: (EditorValue) -> Unit,
    textStyle: TextStyle = TextStyle.Default,
    keyboardType: KeyboardType = KeyboardType.Text,
    imeAction: ImeAction = ImeAction.Unspecified,
    onFocusChange: (Boolean) -> Unit = {},
    onImeActionPerformed: (ImeAction) -> Unit = {},
    visualTransformation: VisualTransformation = VisualTransformation.None,
    onTextLayout: (TextLayoutResult) -> Unit = {},
    onTextInputStarted: (SoftwareKeyboardController) -> Unit = {}
): Unit

Deprecated.

CoreTextField

@Composable fun CoreTextField(
    value: TextFieldValue,
    modifier: Modifier = Modifier,
    onValueChange: (TextFieldValue) -> Unit,
    textStyle: TextStyle = TextStyle.Default,
    keyboardType: KeyboardType = KeyboardType.Text,
    imeAction: ImeAction = ImeAction.Unspecified,
    onImeActionPerformed: (ImeAction) -> Unit = {},
    onFocusChanged: (Boolean) -> Unit = {},
    visualTransformation: VisualTransformation = VisualTransformation.None,
    onTextLayout: (TextLayoutResult) -> Unit = {},
    onTextInputStarted: (SoftwareKeyboardController) -> Unit = {}
): Unit

Base composable that enables users to edit text via hardware or software keyboard.

This composable provides basic text editing functionality, however does not include any decorations such as borders, hints/placeholder.

Whenever the user edits the text, onValueChange is called with the most up to date state represented by TextFieldValue. TextFieldValue contains the text entered by user, as well as selection, cursor and text composition information. Please check TextFieldValue for the description of its contents.

It is crucial that the value provided in the onValueChange is fed back into CoreTextField in order to have the final state of the text being displayed. Example usage:

import androidx.ui.input.TextFieldValue
import androidx.ui.savedinstancestate.savedInstanceState
import androidx.ui.text.CoreTextField

var value by savedInstanceState(saver = TextFieldValue.Saver) { TextFieldValue() }
CoreTextField(
    value = value,
    onValueChange = {
        // it is crucial that the update is fed back into CoreTextField in order to
        // see updates on the text
        value = it
    }
)
Please keep in mind that onValueChange is useful to be informed about the latest state of thetext input by users, however it is generally not recommended to modify the values in theTextFieldValue that you get via onValueChange callback. Any change to the values inTextFieldValue may result in a context reset and end up with input session restart. Sucha scenario would cause glitches in the UI or text input experience for users.
Parameters
value: TextFieldValue The androidx.ui.input.TextFieldValue to be shown in the CoreTextField.
onValueChange: (TextFieldValue) -> Unit Called when the input service updates the values in TextFieldValue.
modifier: Modifier = Modifier optional Modifier for this text field.
textStyle: TextStyle = TextStyle.Default Style configuration that applies at character level such as color, font etc.
keyboardType: KeyboardType = KeyboardType.Text The keyboard type to be used in this text field. Note that this input type is honored by IME and shows corresponding keyboard but this is not guaranteed. For example, some IME may send non-ASCII character even if you set KeyboardType.Ascii.
imeAction: ImeAction = ImeAction.Unspecified The IME action. This IME action is honored by IME and may show specific icons on the keyboard. For example, search icon may be shown if ImeAction.Search is specified. Then, when user tap that key, the onImeActionPerformed callback is called with specified ImeAction.
onFocusChanged: (Boolean) -> Unit = {} Called with true value when the input field gains focus and with false value when the input field loses focus. Use FocusModifier.requestFocus to obtain text input focus to this TextField.
visualTransformation: VisualTransformation = VisualTransformation.None The visual transformation filter for changing the visual representation of the input. By default no visual transformation is applied.
onTextLayout: (TextLayoutResult) -> Unit = {} Callback that is executed when a new text layout is calculated.
onTextInputStarted: (SoftwareKeyboardController) -> Unit = {} Callback that is executed when the initialization has done for communicating with platform text input service, e.g. software keyboard on Android. Called with SoftwareKeyboardController instance which can be used for requesting input show/hide software keyboard.

Paragraph

fun Paragraph(
    text: String,
    style: TextStyle,
    spanStyles: List<AnnotatedString.Range<SpanStyle>> = listOf(),
    placeholders: List<AnnotatedString.Range<Placeholder>> = listOf(),
    maxLines: Int = DefaultMaxLines,
    ellipsis: Boolean = false,
    constraints: ParagraphConstraints,
    density: Density,
    resourceLoader: Font.ResourceLoader
): Paragraph

Lays out a given text with the given constraints. A paragraph is a text that has a single ParagraphStyle.

If the style does not contain any androidx.ui.text.style.TextDirection, androidx.ui.text.style.TextDirection.Content is used as the default value.

Parameters
text: String the text to be laid out
style: TextStyle the TextStyle to be applied to the whole text
spanStyles: List<AnnotatedString.Range<SpanStyle>> = listOf() SpanStyles to be applied to parts of text
placeholders: List<AnnotatedString.Range<Placeholder>> = listOf() a list of placeholder metrics which tells Paragraph where should be left blank to leave space for inline elements.
maxLines: Int = DefaultMaxLines the maximum number of lines that the text can have
ellipsis: Boolean = false whether to ellipsize text, applied only when maxLines is set
constraints: ParagraphConstraints how wide the text is allowed to be
density: Density density of the device
resourceLoader: Font.ResourceLoader Font.ResourceLoader to be used to load the font given in SpanStyles
Exceptions
IllegalArgumentException if ParagraphStyle.textDirection is not set

Paragraph

fun Paragraph(
    paragraphIntrinsics: ParagraphIntrinsics,
    maxLines: Int = DefaultMaxLines,
    ellipsis: Boolean = false,
    constraints: ParagraphConstraints
): Paragraph

Lays out the text in ParagraphIntrinsics with the given constraints. A paragraph is a text that has a single ParagraphStyle.

Parameters
paragraphIntrinsics: ParagraphIntrinsics ParagraphIntrinsics instance
maxLines: Int = DefaultMaxLines the maximum number of lines that the text can have
ellipsis: Boolean = false whether to ellipsize text, applied only when maxLines is set
constraints: ParagraphConstraints how wide the text is allowed to be

ParagraphIntrinsics

fun ParagraphIntrinsics(
    text: String,
    style: TextStyle,
    spanStyles: List<AnnotatedString.Range<SpanStyle>> = listOf(),
    placeholders: List<AnnotatedString.Range<Placeholder>> = listOf(),
    density: Density,
    resourceLoader: Font.ResourceLoader
): ParagraphIntrinsics

Factory method to create a ParagraphIntrinsics.

If the style does not contain any androidx.ui.text.style.TextDirection, androidx.ui.text.style.TextDirection.Content is used as the default value.

TextRange

fun TextRange(index: Int): TextRange

Creates a TextRange where start is equal to end, and the value of those are index.

annotatedString

inline fun annotatedString(builder: AnnotatedString.Builder.() -> Unit): AnnotatedString

Build a new AnnotatedString by populating newly created AnnotatedString.Builder provided by builder.

import androidx.ui.text.SpanStyle
import androidx.ui.text.annotatedString
import androidx.ui.text.withStyle

// create an AnnotatedString using the lambda builder
annotatedString {
    // append "Hello" with red text color
    withStyle(SpanStyle(color = Color.Red)) {
        append("Hello")
    }
    append(" ")
    // append "Hello" with blue text color
    withStyle(SpanStyle(color = Color.Blue)) {
        append("World!")
    }
}
Parameters
builder: AnnotatedString.Builder.() -> Unit lambda to modify AnnotatedString.Builder

lerp

@Stable fun lerp(
    start: ParagraphStyle,
    stop: ParagraphStyle,
    fraction: Float
): ParagraphStyle

Interpolate between two ParagraphStyles.

This will not work well if the styles don't set the same fields.

The fraction argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning start (or something equivalent to start), 1.0 meaning that the interpolation has finished, returning stop (or something equivalent to stop), and values in between meaning that the interpolation is at the relevant point on the timeline between start and stop. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid.

lerp

fun lerp(
    start: SpanStyle,
    stop: SpanStyle,
    fraction: Float
): SpanStyle

Interpolate between two span styles.

This will not work well if the styles don't set the same fields.

The fraction argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning start (or something equivalent to start), 1.0 meaning that the interpolation has finished, returning stop (or something equivalent to stop), and values in between meaning that the interpolation is at the relevant point on the timeline between start and stop. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid.

lerp

fun lerp(
    start: TextStyle,
    stop: TextStyle,
    fraction: Float
): TextStyle

Interpolate between two text styles.

This will not work well if the styles don't set the same fields.

The fraction argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning start (or something equivalent to start), 1.0 meaning that the interpolation has finished, returning stop (or something equivalent to stop), and values in between meaning that the interpolation is at the relevant point on the timeline between start and stop. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid.

resolveDefaults

fun resolveDefaults(
    style: TextStyle,
    direction: LayoutDirection
): TextStyle

Fills missing values in TextStyle with default values and resolve TextDirection.

This function will fill all null or TextUnit.Inherit field with actual values.

Parameters
style: TextStyle a text style to be resolved
direction: LayoutDirection a layout direction to be used for resolving text layout direction algorithm
Return
resolved text style.

Top-level properties

FirstBaseline

val FirstBaseline: HorizontalAlignmentLine

AlignmentLine defined by the baseline of a first line of a CoreText.

LastBaseline

val LastBaseline: HorizontalAlignmentLine

AlignmentLine defined by the baseline of the last line of a CoreText.

Extension functions

appendInlineContent

fun AnnotatedString.Builder.appendInlineContent(
    id: String,
    alternateText: String = REPLACEMENT_CHAR
): Unit

Append an inline content into the AnnotatedString.

Parameters
id: String The id of this inline content, it is referred by the androidx.ui.text.CoreText parameter inlineContent to replace the alternateText to the corresponding composable.
alternateText: String = REPLACEMENT_CHAR The text to be replaced by the inline content. It's displayed when the inlineContent parameter of androidx.ui.text.CoreText doesn't contain id. Accessibility features will also use this text to describe the inline content.
Exceptions
IllegalArgumentException if alternateText has zero length.

capitalize

fun String.capitalize(locale: Locale): String

Returns capitalized String.

Parameters
locale: Locale a locale object
Return
a transformed text

capitalize

fun String.capitalize(localeList: LocaleList): String

Returns capitalized String.

Parameters
localeList: LocaleList a locale list object. If empty locale list object is passed, use current locale instead.
Return
a transformed text

capitalize

fun AnnotatedString.capitalize(localeList: LocaleList = LocaleList.current): AnnotatedString

Create capitalized AnnotatedString

The capitalization sometimes maps different number of characters. This function adjusts the text style and paragraph style ranges to transformed offset.

Note, if the style's offset is middle of the capitalization context, this function won't transform the character, e.g. style starts from between base alphabet character and accent character.

Parameters
localeList: LocaleList = LocaleList.current A locale list used for capitalize mapping. Only the first locale is effective. If empty locale list is passed, use the current locale instead. Note that, this locale is currently ignored since underlying Kotlin method is experimental.
Return
A capitalized string.

decapitalize

fun String.decapitalize(locale: Locale): String

Returns decapitalized String.

Parameters
locale: Locale a locale object
Return
a transformed text

decapitalize

fun String.decapitalize(localeList: LocaleList): String

Returns decapitalized String.

Parameters
localeList: LocaleList a locale list object. If empty locale list object is passed, use current locale instead.

decapitalize

fun AnnotatedString.decapitalize(localeList: LocaleList = LocaleList.current): AnnotatedString

Create capitalized AnnotatedString

The decapitalization sometimes maps different number of characters. This function adjusts the text style and paragraph style ranges to transformed offset.

Note, if the style's offset is middle of the decapitalization context, this function won't transform the character, e.g. style starts from between base alphabet character and accent character.

Parameters
localeList: LocaleList = LocaleList.current A locale list used for decapitalize mapping. Only the first locale is effective. If empty locale list is passed, use the current locale instead. Note that, this locale is currently ignored since underlying Kotlin method is experimental.
Return
A decapitalized string.

subSequence

fun AnnotatedString.subSequence(
    start: Int,
    end: Int
): AnnotatedString

Return a substring for the AnnotatedString and include the styles in the range of start (inclusive) and end (exclusive).

Parameters
start: Int the inclusive start offset of the range
end: Int the exclusive end offset of the range

substring

fun CharSequence.substring(range: TextRange): String

supportsInputMethods

fun SemanticsPropertyReceiver.supportsInputMethods(): Unit

Whether the component supports input methods.

Supporting input methods means that the component provides a connection to IME (keyboard) and is able to accept input from it. This is typically a text field for instance.

toLowerCase

fun String.toLowerCase(locale: Locale): String

Returns lowercase transformed String.

Parameters
locale: Locale a locale object
Return
a transformed text

toLowerCase

fun String.toLowerCase(localeList: LocaleList): String

Returns lowercase transformed String.

Parameters
localeList: LocaleList a locale list object. If empty locale list object is passed, use current locale instead.
Return
a transformed text

toLowerCase

fun AnnotatedString.toLowerCase(localeList: LocaleList = LocaleList.current): AnnotatedString

Create lower case transformed AnnotatedString

The lowercase sometimes maps different number of characters. This function adjusts the text style and paragraph style ranges to transformed offset.

Note, if the style's offset is middle of the lowercase mapping context, this function won't transform the character, e.g. style starts from between base alphabet character and accent character.

Parameters
localeList: LocaleList = LocaleList.current A locale list used for lower case mapping. Only the first locale is effective. If empty locale list is passed, use the current locale instead.
Return
A lowercase transformed string.

toUpperCase

fun String.toUpperCase(locale: Locale): String

Returns uppercase transformed String.

Parameters
locale: Locale a locale object
Return
a transformed text

toUpperCase

fun String.toUpperCase(localeList: LocaleList): String

Returns uppercase transformed String.

Parameters
localeList: LocaleList a locale list object. If empty locale list object is passed, use current locale instead.
Return
a transformed text

toUpperCase

fun AnnotatedString.toUpperCase(localeList: LocaleList = LocaleList.current): AnnotatedString

Create upper case transformed AnnotatedString

The uppercase sometimes maps different number of characters. This function adjusts the text style and paragraph style ranges to transformed offset.

Note, if the style's offset is middle of the uppercase mapping context, this function won't transform the character, e.g. style starts from between base alphabet character and accent character.

Parameters
localeList: LocaleList = LocaleList.current A locale list used for upper case mapping. Only the first locale is effective. If empty locale list is passed, use the current locale instead.
Return
A uppercase transformed string.

withStyle

inline fun <R : Any> AnnotatedString.Builder.withStyle(
    style: SpanStyle,
    crossinline block: AnnotatedString.Builder.() -> R
): R

Pushes style to the AnnotatedString.Builder, executes block and then pops the style.

import androidx.ui.text.SpanStyle
import androidx.ui.text.withStyle

with(AnnotatedString.Builder()) {
    withStyle(SpanStyle(color = Color.Green)) {
        // green text style will be applied to all text in this block
        append("Hello")
    }
    toAnnotatedString()
}
Parameters
style: SpanStyle SpanStyle to be applied
block: AnnotatedString.Builder.() -> R function to be executed
Return
result of the block

withStyle

inline fun <R : Any> AnnotatedString.Builder.withStyle(
    style: ParagraphStyle,
    crossinline block: AnnotatedString.Builder.() -> R
): R

Pushes style to the AnnotatedString.Builder, executes block and then pops the style.

import androidx.ui.text.SpanStyle
import androidx.ui.text.withStyle

with(AnnotatedString.Builder()) {
    withStyle(SpanStyle(color = Color.Green)) {
        // green text style will be applied to all text in this block
        append("Hello")
    }
    toAnnotatedString()
}
Parameters
style: ParagraphStyle SpanStyle to be applied
block: AnnotatedString.Builder.() -> R function to be executed
Return
result of the block

Extension properties

imeAction

var SemanticsPropertyReceiver.imeAction: ImeAction

Contains the IME action provided by the node.

length

val AnnotatedString.length: Int

Returns the length of the AnnotatedString.