ParagraphStyle
Class
Common
class ParagraphStyle(
    val textAlign: TextAlign = TextAlign.Unspecified,
    val textDirection: TextDirection = TextDirection.Unspecified,
    val lineHeight: TextUnit = TextUnit.Unspecified,
    val textIndent: TextIndent? = null,
    val platformStyle: PlatformParagraphStyle? = null,
    val lineHeightStyle: LineHeightStyle? = null,
    val lineBreak: LineBreak = LineBreak.Unspecified,
    val hyphens: Hyphens = Hyphens.Unspecified,
    val textMotion: TextMotion? = null,
) : AnnotatedString.Annotation
Paragraph styling configuration for a paragraph. The difference between SpanStyle and
ParagraphStyle is that, ParagraphStyle can be applied to a whole Paragraph while
SpanStyle can be applied at the character level. Once a portion of the text is marked with a
ParagraphStyle, that portion will be separated from the remaining as if a line feed character
was added.
Parameters
| textAlign | The alignment of the text within the lines of the paragraph. | 
| textDirection | The algorithm to be used to resolve the final text direction: Left To Right or Right To Left. | 
| lineHeight | Line height for the ParagraphinTextUnitunit, e.g. SP or EM. | 
| textIndent | The indentation of the paragraph. | 
| platformStyle | Platform specific ParagraphStyleparameters. | 
| lineHeightStyle | the configuration for line height such as vertical alignment of the line, whether to apply additional space as a result of line height to top of first line top and bottom of last line. The configuration is applied only when a lineHeightis defined. When null,LineHeightStyle.Defaultis used. | 
| lineBreak | The line breaking configuration for the text. | 
| hyphens | The configuration of hyphenation. | 
| textMotion | Text character placement, whether to optimize for animated or static text. | 
Secondary Constructors
constructor(
    textAlign: TextAlign? = null,
    textDirection: TextDirection? = null,
    lineHeight: TextUnit = TextUnit.Unspecified,
    textIndent: TextIndent? = null,
    platformStyle: PlatformParagraphStyle? = null,
    lineHeightStyle: LineHeightStyle? = null,
    lineBreak: LineBreak? = null,
    hyphens: Hyphens? = null,
    textMotion: TextMotion? = null,
) : this(
    textAlign = textAlign ?: TextAlign.Unspecified,
    textDirection = textDirection ?: TextDirection.Unspecified,
    lineHeight = lineHeight,
    textIndent = textIndent,
    platformStyle = platformStyle,
    lineHeightStyle = lineHeightStyle,
    lineBreak = lineBreak ?: LineBreak.Unspecified,
    hyphens = hyphens ?: Hyphens.Unspecified,
    textMotion = textMotion,
)
constructor(
    textAlign: TextAlign? = null,
    textDirection: TextDirection? = null,
    lineHeight: TextUnit = TextUnit.Unspecified,
    textIndent: TextIndent? = null,
) : this(
    textAlign = textAlign ?: TextAlign.Unspecified,
    textDirection = textDirection ?: TextDirection.Unspecified,
    lineHeight = lineHeight,
    textIndent = textIndent,
    platformStyle = null,
    lineHeightStyle = null,
    lineBreak = LineBreak.Unspecified,
    hyphens = Hyphens.Unspecified,
    textMotion = null,
)
constructor(
    textAlign: TextAlign? = null,
    textDirection: TextDirection? = null,
    lineHeight: TextUnit = TextUnit.Unspecified,
    textIndent: TextIndent? = null,
    platformStyle: PlatformParagraphStyle? = null,
    lineHeightStyle: LineHeightStyle? = null,
) : this(
    textAlign = textAlign ?: TextAlign.Unspecified,
    textDirection = textDirection ?: TextDirection.Unspecified,
    lineHeight = lineHeight,
    textIndent = textIndent,
    platformStyle = platformStyle,
    lineHeightStyle = lineHeightStyle,
    lineBreak = LineBreak.Unspecified,
    hyphens = Hyphens.Unspecified,
    textMotion = null,
)
constructor(
    textAlign: TextAlign? = null,
    textDirection: TextDirection? = null,
    lineHeight: TextUnit = TextUnit.Unspecified,
    textIndent: TextIndent? = null,
    platformStyle: PlatformParagraphStyle? = null,
    lineHeightStyle: LineHeightStyle? = null,
    lineBreak: LineBreak? = null,
    hyphens: Hyphens? = null,
) : this(
    textAlign = textAlign ?: TextAlign.Unspecified,
    textDirection = textDirection ?: TextDirection.Unspecified,
    lineHeight = lineHeight,
    textIndent = textIndent,
    platformStyle = platformStyle,
    lineHeightStyle = lineHeightStyle,
    lineBreak = lineBreak ?: LineBreak.Unspecified,
    hyphens = hyphens ?: Hyphens.Unspecified,
    textMotion = null,
)
Properties
Common
Deprecated Kept for backwards compatibility.
val deprecated_boxing_textAlign: TextAlign?
Common
Deprecated Kept for backwards compatibility.
val deprecated_boxing_textDirection: TextDirection?
Common
Deprecated Kept for backwards compatibility.
val deprecated_boxing_hyphens: Hyphens?
Common
Deprecated Kept for backwards compatibility.
val deprecated_boxing_lineBreak: LineBreak?
Functions
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.
operator fun plus(other: ParagraphStyle): ParagraphStyle
Plus operator overload that applies a merge.
fun copy(
        textAlign: TextAlign? = this.textAlign,
        textDirection: TextDirection? = this.textDirection,
        lineHeight: TextUnit = this.lineHeight,
        textIndent: TextIndent? = this.textIndent,
    ): ParagraphStyle
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,
    ): ParagraphStyle
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,
    ): ParagraphStyle
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
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
Code Examples
ParagraphStyleAnnotatedStringsSample
@Composable
fun ParagraphStyleAnnotatedStringsSample() {
    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)
            }
    )
}
ParagraphStyleSample
@Composable
fun ParagraphStyleSample() {
    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,
    )
}
