{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

ParagraphStyle

public final class 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.material.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.material.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)
    }
)
See also
Paragraph
AnnotatedString
SpanStyle
TextStyle

Summary

Public constructors

ParagraphStyle(
    TextAlign textAlign,
    TextDirection textDirection,
    @NonNull TextUnit lineHeight,
    TextIndent textIndent,
    PlatformParagraphStyle platformStyle,
    LineHeightStyle lineHeightStyle,
    LineBreak lineBreak,
    Hyphens hyphens,
    TextMotion textMotion
)

Public methods

final @NonNull ParagraphStyle
copy(
    TextAlign textAlign,
    TextDirection textDirection,
    @NonNull TextUnit lineHeight,
    TextIndent textIndent,
    PlatformParagraphStyle platformStyle,
    LineHeightStyle lineHeightStyle,
    LineBreak lineBreak,
    Hyphens hyphens,
    TextMotion textMotion
)
boolean
equals(Object other)
final Hyphens

The configuration of hyphenation.

final LineBreak

The line breaking configuration for the text.

final @NonNull TextUnit

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

final 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.

final PlatformParagraphStyle

Platform specific ParagraphStyle parameters.

final TextAlign

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

final TextDirection

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

final TextIndent

The indentation of the paragraph.

final TextMotion

Text character placement, whether to optimize for animated or static text.

int
final @NonNull ParagraphStyle

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

final @NonNull ParagraphStyle

Plus operator overload that applies a merge.

@NonNull String

Public constructors

ParagraphStyle

public ParagraphStyle(
    TextAlign textAlign,
    TextDirection textDirection,
    @NonNull TextUnit lineHeight,
    TextIndent textIndent,
    PlatformParagraphStyle platformStyle,
    LineHeightStyle lineHeightStyle,
    LineBreak lineBreak,
    Hyphens hyphens,
    TextMotion textMotion
)
Parameters
TextAlign textAlign

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

TextDirection textDirection

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

@NonNull TextUnit lineHeight

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

TextIndent textIndent

The indentation of the paragraph.

PlatformParagraphStyle platformStyle

Platform specific ParagraphStyle parameters.

LineHeightStyle 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 lineHeight is defined. When null, LineHeightStyle.Default is used.

LineBreak lineBreak

The line breaking configuration for the text.

Hyphens hyphens

The configuration of hyphenation.

TextMotion textMotion

Text character placement, whether to optimize for animated or static text.

Public methods

copy

public final @NonNull ParagraphStyle copy(
    TextAlign textAlign,
    TextDirection textDirection,
    @NonNull TextUnit lineHeight,
    TextIndent textIndent,
    PlatformParagraphStyle platformStyle,
    LineHeightStyle lineHeightStyle,
    LineBreak lineBreak,
    Hyphens hyphens,
    TextMotion textMotion
)

equals

public boolean equals(Object other)

getHyphens

public final Hyphens getHyphens()

The configuration of hyphenation.

getLineBreak

public final LineBreak getLineBreak()

The line breaking configuration for the text.

getLineHeight

public final @NonNull TextUnit getLineHeight()

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

getLineHeightStyle

public final LineHeightStyle getLineHeightStyle()

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 lineHeight is defined. When null, LineHeightStyle.Default is used.

getPlatformStyle

public final PlatformParagraphStyle getPlatformStyle()

Platform specific ParagraphStyle parameters.

getTextAlign

public final TextAlign getTextAlign()

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

getTextDirection

public final TextDirection getTextDirection()

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

getTextIndent

public final TextIndent getTextIndent()

The indentation of the paragraph.

getTextMotion

public final TextMotion getTextMotion()

Text character placement, whether to optimize for animated or static text.

hashCode

public int hashCode()

merge

public final @NonNull ParagraphStyle merge(ParagraphStyle other)

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

public final @NonNull ParagraphStyle plus(@NonNull ParagraphStyle other)

Plus operator overload that applies a merge.

toString

public @NonNull String toString()