ParagraphStyle
-
Cmn
class ParagraphStyle : AnnotatedString.Annotation
Paragraph styling configuration.
Defines styling parameters that apply to a whole paragraph (e.g., alignment, line height).
In contrast to SpanStyle which applies at character level, ParagraphStyle separates the marked text into a new paragraph, as if a line feed character was inserted.
import androidx.compose.material3.Text import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextIndent import androidx.compose.ui.unit.sp val textStyle = TextStyle( textAlign = TextAlign.Justify, lineHeight = 20.sp, textIndent = TextIndent(firstLine = 14.sp, restLine = 3.sp), ) Text( text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor " + "incididunt ut labore et dolore magna aliqua.\nUt enim ad minim veniam, quis " + "nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", style = textStyle, )
import androidx.compose.material3.Text import androidx.compose.ui.text.ParagraphStyle import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.style.TextIndent import androidx.compose.ui.unit.sp val text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor " + "incididunt ut labore et dolore magna aliqua.\nUt enim ad minim veniam, quis " + "nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." val paragraphStyle1 = ParagraphStyle(textIndent = TextIndent(firstLine = 14.sp)) val paragraphStyle2 = ParagraphStyle(lineHeight = 30.sp) Text( text = buildAnnotatedString { append(text) addStyle(paragraphStyle1, 0, text.indexOf('\n') + 1) addStyle(paragraphStyle2, text.indexOf('\n') + 1, text.length) } )
import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.ParagraphStyle import androidx.compose.ui.unit.sp with(AnnotatedString.Builder()) { // push a ParagraphStyle to be applied to any appended text after this point. pushStyle(ParagraphStyle(lineHeight = 18.sp)) // append a paragraph which will have lineHeight 18.sp append("Paragraph One\n") // pop the ParagraphStyle pop() // append new paragraph, this paragraph will not have the line height defined. append("Paragraph Two\n") toAnnotatedString() }
| See also | |
|---|---|
Paragraph |
|
AnnotatedString |
|
SpanStyle |
|
TextStyle |
Summary
Public constructors |
|
|---|---|
ParagraphStyle( |
Cmn
|
Public functions |
||
|---|---|---|
ParagraphStyle |
copy( |
Cmn
|
open operator Boolean |
Cmn
|
|
open Int |
hashCode() |
Cmn
|
ParagraphStyle |
merge(other: ParagraphStyle?)Returns a new paragraph style that is a combination of this style and the given |
Cmn
|
operator ParagraphStyle |
plus(other: ParagraphStyle)Plus operator overload that applies a |
Cmn
|
open String |
toString() |
Cmn
|
Public properties |
||
|---|---|---|
Hyphens? |
This property is deprecated. Kept for backwards compatibility. |
Cmn
|
LineBreak? |
This property is deprecated. Kept for backwards compatibility. |
Cmn
|
TextAlign? |
This property is deprecated. Kept for backwards compatibility. |
Cmn
|
TextDirection? |
This property is deprecated. Kept for backwards compatibility. |
Cmn
|
Hyphens |
hyphenation configuration. |
Cmn
|
LineBreak |
line breaking rules. |
Cmn
|
TextUnit |
line height |
Cmn
|
LineHeightStyle? |
line height distribution configuration |
Cmn
|
PlatformParagraphStyle? |
platform-specific parameters |
Cmn
|
TextAlign |
alignment of the text within the lines of the paragraph. |
Cmn
|
TextDirection |
algorithm used to resolve the final text direction: Left To Right or Right To Left. |
Cmn
|
TextIndent? |
paragraph indentation |
Cmn
|
TextMotion? |
character placement optimization. |
Cmn
|
Public constructors
ParagraphStyle
ParagraphStyle(
textAlign: TextAlign = TextAlign.Unspecified,
textDirection: TextDirection = TextDirection.Unspecified,
lineHeight: TextUnit = TextUnit.Unspecified,
textIndent: TextIndent? = null,
platformStyle: PlatformParagraphStyle? = null,
lineHeightStyle: LineHeightStyle? = null,
lineBreak: LineBreak = LineBreak.Unspecified,
hyphens: Hyphens = Hyphens.Unspecified,
textMotion: TextMotion? = null
)
| Parameters | |
|---|---|
textAlign: TextAlign = TextAlign.Unspecified |
alignment of the text within the lines of the paragraph. |
textDirection: TextDirection = TextDirection.Unspecified |
algorithm used to resolve the final text direction: Left To Right or Right To Left. |
lineHeight: TextUnit = TextUnit.Unspecified |
line height |
textIndent: TextIndent? = null |
paragraph indentation |
platformStyle: PlatformParagraphStyle? = null |
platform-specific parameters |
lineHeightStyle: LineHeightStyle? = null |
line height distribution configuration |
lineBreak: LineBreak = LineBreak.Unspecified |
line breaking rules. |
hyphens: Hyphens = Hyphens.Unspecified |
hyphenation configuration. |
textMotion: TextMotion? = null |
character placement optimization. |
Public functions
copy
fun copy(
textAlign: TextAlign = this.textAlign,
textDirection: TextDirection = this.textDirection,
lineHeight: TextUnit = this.lineHeight,
textIndent: TextIndent? = this.textIndent,
platformStyle: PlatformParagraphStyle? = this.platformStyle,
lineHeightStyle: LineHeightStyle? = this.lineHeightStyle,
lineBreak: LineBreak = this.lineBreak,
hyphens: Hyphens = this.hyphens,
textMotion: TextMotion? = this.textMotion
): ParagraphStyle
merge
fun merge(other: ParagraphStyle? = null): ParagraphStyle
Returns a new paragraph style that is a combination of this style and the given other style.
If the given paragraph style is null, returns this paragraph style.
| Parameters | |
|---|---|
other: ParagraphStyle? = null |
style to merge |
plus
operator fun plus(other: ParagraphStyle): ParagraphStyle
Plus operator overload that applies a merge.
Public properties
textDirection
val textDirection: TextDirection
algorithm used to resolve the final text direction: Left To Right or Right To Left.