androidx.compose.ui.text

TextStyle

Class · from org.jetbrains.compose.ui:ui-text:1.12.2

No hand-written docs yet.

Styling configuration for a Text.

class TextStyle

How to get one

Ready-made values and functions that return it

Used by

Parameters that take a TextStyle.

Properties

brush

val brush: Brush?

The brush to use when drawing text. If not null, overrides color.

color

val color: Color

The text color.

alpha

val alpha: Float

Opacity of text. This value is either provided along side Brush, or via alpha channel in color.

fontSize

val fontSize: TextUnit

The size of glyphs to use when painting the text. This may be TextUnit.Unspecified for inheriting from another TextStyle.

fontWeight

val fontWeight: FontWeight?

The typeface thickness to use when painting the text (e.g., bold).

fontStyle

val fontStyle: FontStyle?

The typeface variant to use when drawing the letters (e.g., italic).

fontSynthesis

val fontSynthesis: FontSynthesis?

Whether to synthesize font weight and/or style when the requested weight or style cannot be found in the provided font family.

fontFamily

val fontFamily: FontFamily?

The font family to be used when rendering the text.

fontFeatureSettings

val fontFeatureSettings: String?

The advanced typography settings provided by font. The format is the same as the CSS font-feature-settings attribute: https://www.w3.org/TR/css-fonts-3/#font-feature-settings-prop

letterSpacing

val letterSpacing: TextUnit

The amount of space to add between each letter.

baselineShift

val baselineShift: BaselineShift?

The amount by which the text is shifted up from the current baseline.

textGeometricTransform

val textGeometricTransform: TextGeometricTransform?

The geometric transformation applied the text.

localeList

val localeList: LocaleList?

The locale list used to select region-specific glyphs.

background

val background: Color

The background color for the text.

textDecoration

val textDecoration: TextDecoration?

The decorations to paint on the text (e.g., an underline).

shadow

val shadow: Shadow?

The shadow effect applied on the text.

drawStyle

val drawStyle: DrawStyle?

Drawing style of text, whether fill in the text while drawing or stroke around the edges.

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 and paragraph direction: Left To Right or Right To Left. If no value is provided the system will use the LayoutDirection as the primary signal.

lineHeight

val lineHeight: TextUnit

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

textIndent

val textIndent: TextIndent?

The indentation of the paragraph.

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.

hyphens

val hyphens: Hyphens

The hyphens configuration of the paragraph.

lineBreak

val lineBreak: LineBreak

The line breaking configuration of the paragraph.

textMotion

val textMotion: TextMotion?

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

Default

val Default: TextStyle

Constant for default text style.

platformStyle

val platformStyle: PlatformTextStyle?

Functions

toSpanStyle

fun toSpanStyle(): SpanStyle

toParagraphStyle

fun toParagraphStyle(): ParagraphStyle

merge

fun merge(
    other: TextStyle? = null,
): TextStyle

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

fun merge(
    color: Color = Color.Unspecified,
    fontSize: TextUnit = TextUnit.Unspecified,
    fontWeight: FontWeight? = null,
    fontStyle: FontStyle? = null,
    fontSynthesis: FontSynthesis? = null,
    fontFamily: FontFamily? = null,
    fontFeatureSettings: String? = null,
    letterSpacing: TextUnit = TextUnit.Unspecified,
    baselineShift: BaselineShift? = null,
    textGeometricTransform: TextGeometricTransform? = null,
    localeList: LocaleList? = null,
    background: Color = Color.Unspecified,
    textDecoration: TextDecoration? = null,
    shadow: Shadow? = null,
    drawStyle: DrawStyle? = null,
    textAlign: TextAlign = TextAlign.Unspecified,
    textDirection: TextDirection = TextDirection.Unspecified,
    lineHeight: TextUnit = TextUnit.Unspecified,
    textIndent: TextIndent? = null,
    lineHeightStyle: LineHeightStyle? = null,
    lineBreak: LineBreak = LineBreak.Unspecified,
    hyphens: Hyphens = Hyphens.Unspecified,
    platformStyle: PlatformTextStyle? = null,
    textMotion: TextMotion? = null,
): TextStyle

Fast merge non-default values and parameters.

fun merge(other: SpanStyle): TextStyle

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

fun merge(other: ParagraphStyle): TextStyle

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

plus

fun plus(other: TextStyle): TextStyle

Plus operator overload that applies a merge.

fun plus(other: ParagraphStyle): TextStyle

Plus operator overload that applies a merge.

fun plus(other: SpanStyle): TextStyle

Plus operator overload that applies a merge.

copy

fun copy(
    color: Color = this.spanStyle.color,
    fontSize: TextUnit = this.spanStyle.fontSize,
    fontWeight: FontWeight? = this.spanStyle.fontWeight,
    fontStyle: FontStyle? = this.spanStyle.fontStyle,
    fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
    fontFamily: FontFamily? = this.spanStyle.fontFamily,
    fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
    letterSpacing: TextUnit = this.spanStyle.letterSpacing,
    baselineShift: BaselineShift? = this.spanStyle.baselineShift,
    textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
    localeList: LocaleList? = this.spanStyle.localeList,
    background: Color = this.spanStyle.background,
    textDecoration: TextDecoration? = this.spanStyle.textDecoration,
    shadow: Shadow? = this.spanStyle.shadow,
    drawStyle: DrawStyle? = this.spanStyle.drawStyle,
    textAlign: TextAlign = this.paragraphStyle.textAlign,
    textDirection: TextDirection = this.paragraphStyle.textDirection,
    lineHeight: TextUnit = this.paragraphStyle.lineHeight,
    textIndent: TextIndent? = this.paragraphStyle.textIndent,
    platformStyle: PlatformTextStyle? = this.platformStyle,
    lineHeightStyle: LineHeightStyle? = this.paragraphStyle.lineHeightStyle,
    lineBreak: LineBreak = this.paragraphStyle.lineBreak,
    hyphens: Hyphens = this.paragraphStyle.hyphens,
    textMotion: TextMotion? = this.paragraphStyle.textMotion,
): TextStyle
fun copy(
    brush: Brush?,
    alpha: Float = this.spanStyle.alpha,
    fontSize: TextUnit = this.spanStyle.fontSize,
    fontWeight: FontWeight? = this.spanStyle.fontWeight,
    fontStyle: FontStyle? = this.spanStyle.fontStyle,
    fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
    fontFamily: FontFamily? = this.spanStyle.fontFamily,
    fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
    letterSpacing: TextUnit = this.spanStyle.letterSpacing,
    baselineShift: BaselineShift? = this.spanStyle.baselineShift,
    textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
    localeList: LocaleList? = this.spanStyle.localeList,
    background: Color = this.spanStyle.background,
    textDecoration: TextDecoration? = this.spanStyle.textDecoration,
    shadow: Shadow? = this.spanStyle.shadow,
    drawStyle: DrawStyle? = this.spanStyle.drawStyle,
    textAlign: TextAlign = this.paragraphStyle.textAlign,
    textDirection: TextDirection = this.paragraphStyle.textDirection,
    lineHeight: TextUnit = this.paragraphStyle.lineHeight,
    textIndent: TextIndent? = this.paragraphStyle.textIndent,
    platformStyle: PlatformTextStyle? = this.platformStyle,
    lineHeightStyle: LineHeightStyle? = this.paragraphStyle.lineHeightStyle,
    lineBreak: LineBreak = this.paragraphStyle.lineBreak,
    hyphens: Hyphens = this.paragraphStyle.hyphens,
    textMotion: TextMotion? = this.paragraphStyle.textMotion,
): TextStyle

hasSameLayoutAffectingAttributes

fun hasSameLayoutAffectingAttributes(other: TextStyle): Boolean

Returns true if text layout affecting attributes between this TextStyle and other are the same.

hasSameDrawAffectingAttributes

fun hasSameDrawAffectingAttributes(other: TextStyle): Boolean
Library docs

Styling configuration for a Text.