ParagraphStyle
-
Cmn
class ParagraphStyle : 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.
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( |
Cmn
|
Public functions |
||
|---|---|---|
ParagraphStyle |
copy( |
Cmn
|
open operator Boolean |
Cmn
|
|
open Int |
hashCode() |
Cmn
|
ParagraphStyle |
merge(other: ParagraphStyle?)Returns a new paragraph style that is a combination of this style and the given |
Cmn
|
operator ParagraphStyle |
plus(other: ParagraphStyle)Plus operator overload that applies a |
Cmn
|
open String |
toString() |
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 |
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 |
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 |
textIndent: TextIndent? = null |
The indentation of the paragraph. |
platformStyle: PlatformParagraphStyle? = null |
Platform specific |
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 |
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
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.
Public properties
lineHeightStyle
val 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.
platformStyle
val platformStyle: PlatformParagraphStyle?
Platform specific ParagraphStyle parameters.
textDirection
val textDirection: TextDirection
The algorithm to be used to resolve the final text direction: Left To Right or Right To Left.
textMotion
val textMotion: TextMotion?
Text character placement, whether to optimize for animated or static text.