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.
AndroidLineBreakSample
@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),
)
}
LineBreakSample
@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),
)
}