LineBreak
-
Cmn
value class LineBreak
Configures line breaking behavior when text wraps automatically to fit its container.
Offers presets for common use cases:
| Preset | Use Case |
Simple |
Text fields and inputs |
Heading |
Titles and short text |
Paragraph |
Body text and long passages |
import androidx.compose.material3.Text import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.style.LineBreak import androidx.compose.ui.unit.sp 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), )
Customize Android behavior using:
-
Strategy: Balances layout speed against formatting quality (e.g., greedy vs. paragraph-optimized breaking). -
Strictness: Adjusts line-breaking rules for East Asian languages (Chinese, Japanese, and Korean), determining which characters can start or end a line. -
WordBreak: Specifies word boundary rules, such as default spacing-based breaking or phrase-based breaking (ideal for titles).
import androidx.compose.material3.Text import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.style.LineBreak import androidx.compose.ui.unit.sp 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), )
Summary
Nested types |
|---|
value class LineBreak.StrategyThe strategy used for line breaking. |
value class LineBreak.StrictnessDescribes the strictness of line breaking, determining before which characters line breaks can be inserted. |
value class LineBreak.WordBreakDescribes how line breaks should be inserted within words. |
Public companion properties |
||
|---|---|---|
LineBreak |
Looser breaking rules, suitable for short text such as titles or narrow newspaper columns. |
Cmn
android
|
LineBreak |
Slower, higher quality line breaking for improved readability. |
Cmn
android
|
LineBreak |
Basic, fast line breaking. |
Cmn
android
|
LineBreak |
Represents an unset |
Cmn
android
|
Public constructors |
|
|---|---|
LineBreak(This represents a configuration for line breaking on Android, describing |
android
|
Public functions |
||
|---|---|---|
LineBreak |
copy( |
android
|
open String |
toString() |
android
|
Public properties |
||
|---|---|---|
LineBreak.Strategy |
android
|
|
LineBreak.Strictness |
android
|
|
LineBreak.WordBreak |
android
|
Extension properties |
||
|---|---|---|
Boolean |
Returns |
Cmn
|
Public companion properties
Heading
val Heading: LineBreak
Looser breaking rules, suitable for short text such as titles or narrow newspaper columns. For longer lines of text, use Paragraph for improved readability.
Paragraph
val Paragraph: LineBreak
Slower, higher quality line breaking for improved readability. Suitable for larger amounts of text.
Public constructors
LineBreak
LineBreak(
strategy: LineBreak.Strategy,
strictness: LineBreak.Strictness,
wordBreak: LineBreak.WordBreak
)
This represents a configuration for line breaking on Android, describing Strategy, Strictness, and WordBreak.
| Parameters | |
|---|---|
strategy: LineBreak.Strategy |
defines the algorithm that inserts line breaks |
strictness: LineBreak.Strictness |
defines the line breaking rules |
wordBreak: LineBreak.WordBreak |
defines how words are broken |
Public functions
copy
fun copy(
strategy: LineBreak.Strategy = this.strategy,
strictness: LineBreak.Strictness = this.strictness,
wordBreak: LineBreak.WordBreak = this.wordBreak
): LineBreak
Public properties
Extension properties
LineBreak.isSpecified
val LineBreak.isSpecified: Boolean
Returns true if it is not LineBreak.Unspecified.
| See also | |
|---|---|
Unspecified |