← Back to Foundation
CoreText
Overview
Code Examples
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.compose.foundation.Text, which is a higher level Text element that contains semantics and consumes style information from a theme.
@param text AnnotatedString encoding a styled text. @param modifier Modifier to apply to this layout node. @param style Style configuration for the text such as color, font, line height etc. @param softWrap 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. @param overflow How visual overflow should be handled. @param maxLines 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. @param inlineContent 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. @param onTextLayout Callback that is executed when a new text layout is calculated.
Overloads
CoreText
@Composable
@InternalTextApi
@OptIn(ExperimentalTextApi::class)
fun CoreText(
text: AnnotatedString,
modifier: Modifier = Modifier,
style: TextStyle,
softWrap: Boolean,
overflow: TextOverflow,
maxLines: Int,
inlineContent: Map<String, InlineTextContent>,
onTextLayout: (TextLayoutResult) -> Unit
)
Parameters
Name | Description |
---|---|
text | AnnotatedString encoding a styled text. |
modifier | Modifier to apply to this layout node. |
style | Style configuration for the text such as color, font, line height etc. |
softWrap | 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 | How visual overflow should be handled. |
maxLines | 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 | 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 | Callback that is executed when a new text layout is calculated |