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)
    }
)

Summary

Public constructors

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

Public functions

ParagraphStyle
copy(
    textAlign: TextAlign,
    textDirection: TextDirection,
    lineHeight: TextUnit,
    textIndent: TextIndent?,
    platformStyle: PlatformParagraphStyle?,
    lineHeightStyle: LineHeightStyle?,
    lineBreak: LineBreak,
    hyphens: Hyphens,
    textMotion: TextMotion?
)
Cmn
open operator Boolean
equals(other: Any?)
Cmn
open Int
Cmn
ParagraphStyle

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

Cmn
operator ParagraphStyle

Plus operator overload that applies a merge.

Cmn
open String
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

The configuration of hyphenation.

Cmn
LineBreak

The line breaking configuration for the text.

Cmn
TextUnit

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

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

Cmn
PlatformParagraphStyle?

Platform specific ParagraphStyle parameters.

Cmn
TextAlign

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

Cmn
TextDirection

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

Cmn
TextIndent?

The indentation of the paragraph.

Cmn
TextMotion?

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

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

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

textDirection: TextDirection = TextDirection.Unspecified

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

lineHeight: TextUnit = TextUnit.Unspecified

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

textIndent: TextIndent? = null

The indentation of the paragraph.

platformStyle: PlatformParagraphStyle? = null

Platform specific ParagraphStyle parameters.

lineHeightStyle: LineHeightStyle? = null

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 = LineBreak.Unspecified

The line breaking configuration for the text.

hyphens: Hyphens = Hyphens.Unspecified

The configuration of hyphenation.

textMotion: TextMotion? = null

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

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

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

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.

plus

operator fun plus(other: ParagraphStyle): ParagraphStyle

Plus operator overload that applies a merge.

toString

open fun toString(): String

Public properties

deprecated_boxing_hyphens

val deprecated_boxing_hyphensHyphens?

deprecated_boxing_lineBreak

val deprecated_boxing_lineBreakLineBreak?

deprecated_boxing_textAlign

val deprecated_boxing_textAlignTextAlign?

deprecated_boxing_textDirection

val deprecated_boxing_textDirectionTextDirection?

hyphens

val hyphensHyphens

The configuration of hyphenation.

lineBreak

val lineBreakLineBreak

The line breaking configuration for the text.

lineHeight

val lineHeightTextUnit

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

lineHeightStyle

val lineHeightStyleLineHeightStyle?

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.

platformStyle

val platformStylePlatformParagraphStyle?

Platform specific ParagraphStyle parameters.

textAlign

val textAlignTextAlign

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

textDirection

val textDirectionTextDirection

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

textIndent

val textIndentTextIndent?

The indentation of the paragraph.

textMotion

val textMotionTextMotion?

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