Google is committed to advancing racial equity for Black communities. See how.

ParagraphStyle

@Immutable data class ParagraphStyle
kotlin.Any
   ↳ androidx.compose.ui.text.ParagraphStyle

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.

import androidx.compose.foundation.Text
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextIndent

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.foundation.Text
import androidx.compose.ui.text.ParagraphStyle
import androidx.compose.ui.text.annotatedString
import androidx.compose.ui.text.style.TextIndent

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 = annotatedString {
        append(text)
        addStyle(paragraphStyle1, 0, text.indexOf('\n') + 1)
        addStyle(paragraphStyle2, text.indexOf('\n') + 1, text.length)
    }
)

Summary

Public constructors
<init>(textAlign: TextAlign? = null, textDirection: TextDirection? = null, lineHeight: TextUnit = TextUnit.Inherit, textIndent: TextIndent? = null)

Paragraph styling configuration for a paragraph.

Public methods
ParagraphStyle
merge(other: ParagraphStyle? = null)

Returns a new paragraph style that is a combination of this style and the given other style.

operator ParagraphStyle

Plus operator overload that applies a merge.

Properties
TextUnit

Line height for the Paragraph in TextUnit unit, e.

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.

TextIndent?

The indentation of the paragraph.

Public constructors

<init>

ParagraphStyle(
    textAlign: TextAlign? = null,
    textDirection: TextDirection? = null,
    lineHeight: TextUnit = TextUnit.Inherit,
    textIndent: TextIndent? = null)

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.

import androidx.compose.foundation.Text
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextIndent

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.foundation.Text
import androidx.compose.ui.text.ParagraphStyle
import androidx.compose.ui.text.annotatedString
import androidx.compose.ui.text.style.TextIndent

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 = annotatedString {
        append(text)
        addStyle(paragraphStyle1, 0, text.indexOf('\n') + 1)
        addStyle(paragraphStyle2, text.indexOf('\n') + 1, text.length)
    }
)
Parameters
textAlign: TextAlign? = null The alignment of the text within the lines of the paragraph.
textDirection: TextDirection? = null The algorithm to be used to resolve the final text direction: Left To Right or Right To Left.
textIndent: TextIndent? = null The indentation of the paragraph.
lineHeight: TextUnit = TextUnit.Inherit Line height for the Paragraph in TextUnit unit, e.g. SP or EM.

Public methods

merge

@Stable 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.

plus

@Stable operator fun plus(other: ParagraphStyle): ParagraphStyle

Plus operator overload that applies a merge.

Properties

lineHeight

val lineHeight: TextUnit

Line height for the Paragraph in TextUnit unit, e.g. SP or EM.

textAlign

val textAlign: TextAlign?

The alignment of the text within the lines of the paragraph.

textDirection

val textDirection: TextDirection?

The algorithm to be used to resolve the final text direction: Left To Right or Right To Left.

textIndent

val textIndent: TextIndent?

The indentation of the paragraph.