androidx.compose.foundation.text
BasicText
Composable function · from org.jetbrains.compose.foundation:foundation:1.12.2
BasicText shows text without any theme. It doesn't read the Material colors or the text style of the theme; you pass everything in style.
Use Text in Material apps. It uses BasicText inside, and adds the theme's text style and content color. Use BasicText only when you build your own design system without Material.
BasicText("Hello", style = TextStyle(fontSize = 18.sp, color = Color.DarkGray))
Plain
A String.
@Composable
fun BasicText(
text: String,
modifier: Modifier = Modifier,
style: TextStyle = TextStyle.Default,
onTextLayout: ((TextLayoutResult) -> Unit)? = null,
overflow: TextOverflow = TextOverflow.Clip,
softWrap: Boolean = true,
maxLines: Int = Int.MAX_VALUE,
minLines: Int = 1,
color: ColorProducer? = null,
autoSize: TextAutoSize? = null,
)
text: StringRequired
text: StringRequiredThe text to show. An AnnotatedString can mix styles, made with buildAnnotatedString { }.
modifier: ModifierOptional
modifier: ModifierOptionalDefault: Modifier
Changes size, padding, or position. See the Modifier guide.
style: TextStyleOptional
style: TextStyleOptionalDefault: TextStyle.Default
Font, size, color, line height and more, as one TextStyle.
onTextLayout: ((TextLayoutResult) -> Unit)?Optional
onTextLayout: ((TextLayoutResult) -> Unit)?OptionalDefault: null
Called with the measured text: line count, positions, whether it was cut off.
overflow: TextOverflowOptional
overflow: TextOverflowOptionalDefault: TextOverflow.Clip
What happens when the text doesn't fit: cut (Clip), or Ellipsis (…).
softWrap: BooleanOptional
softWrap: BooleanOptionalDefault: true
Set to false to keep the text on one line.
maxLines: IntOptional
maxLines: IntOptionalDefault: Int.MAX_VALUE
The most lines. More are cut off, as set by overflow.
minLines: IntOptional
minLines: IntOptionalDefault: 1
The fewest lines. The text takes that much height even if it is shorter.
color: ColorProducer?Optional
color: ColorProducer?OptionalDefault: null
The text color, read each time it is drawn. Cheap to animate. Overrides the color in style.
autoSize: TextAutoSize?OptionalSince 1.8
autoSize: TextAutoSize?OptionalSince 1.8Default: null
Makes the font smaller until the text fits. Use TextAutoSize.StepBased().
Styled
An AnnotatedString with several styles, and inline content.
@Composable
fun BasicText(
text: AnnotatedString,
modifier: Modifier = Modifier,
style: TextStyle = TextStyle.Default,
onTextLayout: ((TextLayoutResult) -> Unit)? = null,
overflow: TextOverflow = TextOverflow.Clip,
softWrap: Boolean = true,
maxLines: Int = Int.MAX_VALUE,
minLines: Int = 1,
inlineContent: Map<String, InlineTextContent> = mapOf(),
color: ColorProducer? = null,
autoSize: TextAutoSize? = null,
)
text: AnnotatedStringRequired
text: AnnotatedStringRequiredThe text to show. An AnnotatedString can mix styles, made with buildAnnotatedString { }.
inlineContent: Map<String, InlineTextContent>Optional
inlineContent: Map<String, InlineTextContent>OptionalDefault: mapOf()
Composables placed inside the text, like an icon. Mark their places with appendInlineContent(id) in the AnnotatedString.
Same as above: modifier, style, onTextLayout, overflow, softWrap, maxLines, minLines, color, autoSize.