ParagraphStyle

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

Paragraph styling configuration for a paragraph. The difference between TextStyle and ParagraphStyle is that, ParagraphStyle can be applied to a whole Paragraph while TextStyle 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.ui.core.Text
import androidx.ui.text.ParagraphStyle
import androidx.ui.text.style.TextIndent

val paragraphStyle = ParagraphStyle(
    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.",
    paragraphStyle = paragraphStyle
)
import androidx.ui.core.Text
import androidx.ui.text.AnnotatedString
import androidx.ui.text.ParagraphStyle
import androidx.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(
    textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr,
    textIndent = TextIndent(firstLine = 14.sp)
)
val paragraphStyle2 = ParagraphStyle(
    lineHeight = 30.sp,
    textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
)

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, textDirectionAlgorithm: TextDirectionAlgorithm? = 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.

Properties

TextUnit

Line height for the Paragraph in TextUnit unit, e.

TextAlign?

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

TextDirectionAlgorithm?

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,
    textDirectionAlgorithm: TextDirectionAlgorithm? = null,
    lineHeight: TextUnit = TextUnit.Inherit,
    textIndent: TextIndent? = null)

Paragraph styling configuration for a paragraph. The difference between TextStyle and ParagraphStyle is that, ParagraphStyle can be applied to a whole Paragraph while TextStyle 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.ui.core.Text
import androidx.ui.text.ParagraphStyle
import androidx.ui.text.style.TextIndent

val paragraphStyle = ParagraphStyle(
    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.",
    paragraphStyle = paragraphStyle
)
import androidx.ui.core.Text
import androidx.ui.text.AnnotatedString
import androidx.ui.text.ParagraphStyle
import androidx.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(
    textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr,
    textIndent = TextIndent(firstLine = 14.sp)
)
val paragraphStyle2 = ParagraphStyle(
    lineHeight = 30.sp,
    textDirectionAlgorithm = TextDirectionAlgorithm.ContentOrLtr
)

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.
textDirectionAlgorithm: TextDirectionAlgorithm? = 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

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.

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.

textDirectionAlgorithm

val textDirectionAlgorithm: TextDirectionAlgorithm?

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.