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

The text to show. An AnnotatedString can mix styles, made with buildAnnotatedString { }.

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position. See the Modifier guide.

style: TextStyleOptional

Default: TextStyle.Default

Font, size, color, line height and more, as one TextStyle.

onTextLayout: ((TextLayoutResult) -> Unit)?Optional

Default: null

Called with the measured text: line count, positions, whether it was cut off.

overflow: TextOverflowOptional

Default: TextOverflow.Clip

What happens when the text doesn't fit: cut (Clip), or Ellipsis (…).

softWrap: BooleanOptional

Default: true

Set to false to keep the text on one line.

maxLines: IntOptional

Default: Int.MAX_VALUE

The most lines. More are cut off, as set by overflow.

minLines: IntOptional

Default: 1

The fewest lines. The text takes that much height even if it is shorter.

color: ColorProducer?Optional

Default: null

The text color, read each time it is drawn. Cheap to animate. Overrides the color in style.

autoSize: TextAutoSize?OptionalSince 1.8

Default: 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

The text to show. An AnnotatedString can mix styles, made with buildAnnotatedString { }.

inlineContent: Map<String, InlineTextContent>Optional

Default: 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.