Text
Functions summary
Unit |
@ComposableHigh level element that displays text and provides semantics / accessibility information. |
Unit |
@ComposableHigh level element that displays text and provides semantics / accessibility information. |
Functions
Text
@Composable
fun Text(
text: String,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
fontSize: TextUnit = TextUnit.Unspecified,
fontStyle: FontStyle? = null,
fontWeight: FontWeight? = null,
fontFamily: FontFamily? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
textDecoration: TextDecoration? = null,
textAlign: TextAlign? = LocalTextConfiguration.current.textAlign,
lineHeight: TextUnit = TextUnit.Unspecified,
overflow: TextOverflow = LocalTextConfiguration.current.overflow,
softWrap: Boolean = true,
maxLines: Int = LocalTextConfiguration.current.maxLines,
minLines: Int = 1,
onTextLayout: (TextLayoutResult) -> Unit = {},
style: TextStyle = LocalTextStyle.current
): Unit
High level element that displays text and provides semantics / accessibility information.
The default style uses the LocalTextStyle provided by the MaterialTheme / components. If you are setting your own style, you may want to consider first retrieving LocalTextStyle, and using TextStyle.copy to keep any theme defined attributes, only modifying the specific attributes you want to override.
For ease of use, commonly used parameters from TextStyle are also present here. The order of precedence is as follows:
-
If a parameter is explicitly set here (i.e, it is not
nullorTextUnit.Unspecified), then this parameter will always be used. -
If a parameter is not set, (
nullorTextUnit.Unspecified), then the corresponding value fromstylewill be used instead.
Additionally, for color, if color is not set, and style does not have a color, then LocalContentColor will be used.
| Parameters | |
|---|---|
text: String |
The text to be displayed. |
modifier: Modifier = Modifier |
|
color: Color = Color.Unspecified |
|
fontSize: TextUnit = TextUnit.Unspecified |
The size of glyphs to use when painting the text. See |
fontStyle: FontStyle? = null |
The typeface variant to use when drawing the letters (e.g., italic). See |
fontWeight: FontWeight? = null |
The typeface thickness to use when painting the text (e.g., |
fontFamily: FontFamily? = null |
The font family to be used when rendering the text. See |
letterSpacing: TextUnit = TextUnit.Unspecified |
The amount of space to add between each letter. See |
textDecoration: TextDecoration? = null |
The decorations to paint on the text (e.g., an underline). See |
textAlign: TextAlign? = LocalTextConfiguration.current.textAlign |
The alignment of the text within the lines of the paragraph. See |
lineHeight: TextUnit = TextUnit.Unspecified |
Line height for the |
overflow: TextOverflow = LocalTextConfiguration.current.overflow |
How visual overflow should be handled. |
softWrap: Boolean = true |
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 |
maxLines: Int = LocalTextConfiguration.current.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 |
minLines: Int = 1 |
The minimum height in terms of minimum number of visible lines. It is required that 1 <= |
onTextLayout: (TextLayoutResult) -> Unit = {} |
Callback that is executed when a new text layout is calculated. A |
style: TextStyle = LocalTextStyle.current |
Style configuration for the text such as color, font, line height etc. |
Text
@Composable
fun Text(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
fontSize: TextUnit = TextUnit.Unspecified,
fontStyle: FontStyle? = null,
fontWeight: FontWeight? = null,
fontFamily: FontFamily? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
textDecoration: TextDecoration? = null,
textAlign: TextAlign? = LocalTextConfiguration.current.textAlign,
lineHeight: TextUnit = TextUnit.Unspecified,
overflow: TextOverflow = LocalTextConfiguration.current.overflow,
softWrap: Boolean = true,
maxLines: Int = LocalTextConfiguration.current.maxLines,
minLines: Int = 1,
inlineContent: Map<String, InlineTextContent> = mapOf(),
onTextLayout: (TextLayoutResult) -> Unit = {},
style: TextStyle = LocalTextStyle.current
): Unit
High level element that displays text and provides semantics / accessibility information.
The default style uses the LocalTextStyle provided by the MaterialTheme / components. If you are setting your own style, you may want to consider first retrieving LocalTextStyle, and using TextStyle.copy to keep any theme defined attributes, only modifying the specific attributes you want to override.
For ease of use, commonly used parameters from TextStyle are also present here. The order of precedence is as follows:
-
If a parameter is explicitly set here (i.e, it is not
nullorTextUnit.Unspecified), then this parameter will always be used. -
If a parameter is not set, (
nullorTextUnit.Unspecified), then the corresponding value fromstylewill be used instead.
Additionally, for color, if color is not set, and style does not have a color, then LocalContentColor will be used.
| Parameters | |
|---|---|
text: AnnotatedString |
The text to be displayed, where |
modifier: Modifier = Modifier |
|
color: Color = Color.Unspecified |
|
fontSize: TextUnit = TextUnit.Unspecified |
The size of glyphs to use when painting the text. See |
fontStyle: FontStyle? = null |
The typeface variant to use when drawing the letters (e.g., italic). See |
fontWeight: FontWeight? = null |
The typeface thickness to use when painting the text (e.g., |
fontFamily: FontFamily? = null |
The font family to be used when rendering the text. See |
letterSpacing: TextUnit = TextUnit.Unspecified |
The amount of space to add between each letter. See |
textDecoration: TextDecoration? = null |
The decorations to paint on the text (e.g., an underline). See |
textAlign: TextAlign? = LocalTextConfiguration.current.textAlign |
The alignment of the text within the lines of the paragraph. See |
lineHeight: TextUnit = TextUnit.Unspecified |
Line height for the |
overflow: TextOverflow = LocalTextConfiguration.current.overflow |
How visual overflow should be handled. |
softWrap: Boolean = true |
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 |
maxLines: Int = LocalTextConfiguration.current.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 |
minLines: Int = 1 |
The minimum height in terms of minimum number of visible lines. It is required that 1 <= |
inlineContent: Map<String, InlineTextContent> = mapOf() |
A map store composables that replaces certain ranges of the text. It's used to insert composables into text layout. Check |
onTextLayout: (TextLayoutResult) -> Unit = {} |
Callback that is executed when a new text layout is calculated. A |
style: TextStyle = LocalTextStyle.current |
Style configuration for the text such as color, font, line height etc. |