Google is committed to advancing racial equity for Black communities. See how.

TextStyle

@Immutable data class TextStyle
kotlin.Any
   ↳ androidx.compose.ui.text.TextStyle

Styling configuration for a Text.

import androidx.compose.foundation.Text
import androidx.compose.ui.text.TextStyle

Text(
    text = "Demo Text",
    style = TextStyle(
        color = Color.Red,
        fontSize = 16.sp,
        fontFamily = FontFamily.Monospace,
        fontWeight = FontWeight.W800,
        fontStyle = FontStyle.Italic,
        letterSpacing = 0.5.em,
        background = Color.LightGray,
        textDecoration = TextDecoration.Underline
    )
)

Summary

Public constructors
<init>(color: Color = Color.Unset, fontSize: TextUnit = TextUnit.Inherit, fontWeight: FontWeight? = null, fontStyle: FontStyle? = null, fontSynthesis: FontSynthesis? = null, fontFamily: FontFamily? = null, fontFeatureSettings: String? = null, letterSpacing: TextUnit = TextUnit.Inherit, baselineShift: BaselineShift? = null, textGeometricTransform: TextGeometricTransform? = null, localeList: LocaleList? = null, background: Color = Color.Unset, textDecoration: TextDecoration? = null, shadow: Shadow? = null, textAlign: TextAlign? = null, textDirection: TextDirection? = null, lineHeight: TextUnit = TextUnit.Inherit, textIndent: TextIndent? = null)

Styling configuration for a Text.

Public methods
TextStyle
merge(other: TextStyle? = null)

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

TextStyle
merge(other: SpanStyle)

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

TextStyle

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

operator TextStyle
plus(other: TextStyle)

Plus operator overload that applies a merge.

operator TextStyle

Plus operator overload that applies a merge.

operator TextStyle
plus(other: SpanStyle)

Plus operator overload that applies a merge.

ParagraphStyle

SpanStyle

Properties
Color

The background color for the text.

BaselineShift?

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

Color

The text color.

FontFamily?

The font family to be used when rendering the text.

String?

The advanced typography settings provided by font.

TextUnit

The size of glyphs to use when painting the text.

FontStyle?

The typeface variant to use when drawing the letters (e.

FontSynthesis?

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

FontWeight?

The typeface thickness to use when painting the text (e.

TextUnit

The amount of space to add between each letter.

TextUnit

Line height for the Paragraph in TextUnit unit, e.

LocaleList?

The locale list used to select region-specific glyphs.

Shadow?

The shadow effect applied on the text.

TextAlign?

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

TextDecoration?

The decorations to paint on the text (e.

TextDirection?

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

TextGeometricTransform?

The geometric transformation applied the text.

TextIndent?

The indentation of the paragraph.

Companion properties
TextStyle

Constant for default text style.

Public constructors

<init>

TextStyle(
    color: Color = Color.Unset,
    fontSize: TextUnit = TextUnit.Inherit,
    fontWeight: FontWeight? = null,
    fontStyle: FontStyle? = null,
    fontSynthesis: FontSynthesis? = null,
    fontFamily: FontFamily? = null,
    fontFeatureSettings: String? = null,
    letterSpacing: TextUnit = TextUnit.Inherit,
    baselineShift: BaselineShift? = null,
    textGeometricTransform: TextGeometricTransform? = null,
    localeList: LocaleList? = null,
    background: Color = Color.Unset,
    textDecoration: TextDecoration? = null,
    shadow: Shadow? = null,
    textAlign: TextAlign? = null,
    textDirection: TextDirection? = null,
    lineHeight: TextUnit = TextUnit.Inherit,
    textIndent: TextIndent? = null)

Styling configuration for a Text.

import androidx.compose.foundation.Text
import androidx.compose.ui.text.TextStyle

Text(
    text = "Demo Text",
    style = TextStyle(
        color = Color.Red,
        fontSize = 16.sp,
        fontFamily = FontFamily.Monospace,
        fontWeight = FontWeight.W800,
        fontStyle = FontStyle.Italic,
        letterSpacing = 0.5.em,
        background = Color.LightGray,
        textDecoration = TextDecoration.Underline
    )
)
Parameters
color: Color = Color.Unset The text color.
fontSize: TextUnit = TextUnit.Inherit The size of glyphs to use when painting the text. This may be TextUnit.Inherit for inheriting from another TextStyle.
fontWeight: FontWeight? = null The typeface thickness to use when painting the text (e.g., bold).
fontStyle: FontStyle? = null The typeface variant to use when drawing the letters (e.g., italic).
fontSynthesis: FontSynthesis? = null Whether to synthesize font weight and/or style when the requested weight or style cannot be found in the provided custom font family.
fontFamily: FontFamily? = null The font family to be used when rendering the text.
fontFeatureSettings: String? = null 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: TextUnit = TextUnit.Inherit The amount of space to add between each letter.
baselineShift: BaselineShift? = null The amount by which the text is shifted up from the current baseline.
textGeometricTransform: TextGeometricTransform? = null The geometric transformation applied the text.
localeList: LocaleList? = null The locale list used to select region-specific glyphs.
background: Color = Color.Unset The background color for the text.
textDecoration: TextDecoration? = null The decorations to paint on the text (e.g., an underline).
shadow: Shadow? = null The shadow effect applied on the text.
textAlign: TextAlign? = null The alignment of the text within the lines of the paragraph.
textDirection: TextDirection? = null 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.
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

@Stable fun merge(other: TextStyle? = null): TextStyle

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

other text style's null or inherit properties are replaced with the non-null properties of this text style. Another way to think of it is that the "missing" properties of the other style are filled by the properties of this style.

If the given text style is null, returns this text style.

merge

@Stable fun merge(other: SpanStyle): TextStyle

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

See Also

merge

@Stable fun merge(other: ParagraphStyle): TextStyle

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

See Also

plus

@Stable operator fun plus(other: TextStyle): TextStyle

Plus operator overload that applies a merge.

plus

@Stable operator fun plus(other: ParagraphStyle): TextStyle

Plus operator overload that applies a merge.

plus

@Stable operator fun plus(other: SpanStyle): TextStyle

Plus operator overload that applies a merge.

toParagraphStyle

@Stable fun toParagraphStyle(): ParagraphStyle

toSpanStyle

@Stable fun toSpanStyle(): SpanStyle

Properties

background

val background: Color

The background color for the text.

baselineShift

val baselineShift: BaselineShift?

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

color

val color: Color

The text color.

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

fontSize

val fontSize: TextUnit

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

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 custom font family.

fontWeight

val fontWeight: FontWeight?

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

letterSpacing

val letterSpacing: TextUnit

The amount of space to add between each letter.

lineHeight

val lineHeight: TextUnit

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

localeList

val localeList: LocaleList?

The locale list used to select region-specific glyphs.

shadow

val shadow: Shadow?

The shadow effect applied on the text.

textAlign

val textAlign: TextAlign?

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

textDecoration

val textDecoration: TextDecoration?

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

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.

textGeometricTransform

val textGeometricTransform: TextGeometricTransform?

The geometric transformation applied the text.

textIndent

val textIndent: TextIndent?

The indentation of the paragraph.

Companion properties

Default

@Stable val Default: TextStyle

Constant for default text style.