Class

LineBreak

When soft wrap is enabled and the width of the text exceeds the width of its container, line breaks are inserted in the text to split it over multiple lines.

LineBreakSample

@Sampled
@Composable
fun LineBreakSample() {
    Text(
        text = "Title of an article",
        style = TextStyle(fontSize = 20.sp, lineBreak = LineBreak.Heading),
    )

    Text(
        text = "A long paragraph in an article",
        style = TextStyle(lineBreak = LineBreak.Paragraph),
    )
}

AndroidLineBreakSample

@Sampled
@Composable
fun AndroidLineBreakSample() {
    val customTitleLineBreak =
        LineBreak(
            strategy = LineBreak.Strategy.Simple,
            strictness = LineBreak.Strictness.Loose,
            wordBreak = LineBreak.WordBreak.Default,
        )

    Text(
        text = "Title of an article",
        style = TextStyle(fontSize = 20.sp, lineBreak = customTitleLineBreak),
    )

    val defaultStrictnessParagraphLineBreak =
        LineBreak.Paragraph.copy(strictness = LineBreak.Strictness.Default)

    Text(
        text = "A long paragraph in an article",
        style = TextStyle(lineBreak = defaultStrictnessParagraphLineBreak),
    )
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: