🌈 Create new beautiful Compose Gradients with our new wesite ->
Class

SpanStyle

Styling configuration that applies at the character level.

Source set: Common
public class SpanStyle internal constructor(
    // The fill to draw text, a unified representation of Color and Brush.
    internal val textForegroundStyle: TextForegroundStyle,
    public val fontSize: TextUnit = TextUnit.Unspecified,
    public val fontWeight: FontWeight? = null,
    public val fontStyle: FontStyle? = null,
    public val fontSynthesis: FontSynthesis? = null,
    public val fontFamily: FontFamily? = null,
    public val fontFeatureSettings: String? = null,
    public val letterSpacing: TextUnit = TextUnit.Unspecified,
    public val baselineShift: BaselineShift? = null,
    public val textGeometricTransform: TextGeometricTransform? = null,
    public val localeList: LocaleList? = null,
    public val background: Color = Color.Unspecified,
    public val textDecoration: TextDecoration? = null,
    public val shadow: Shadow? = null,
    public val platformStyle: PlatformSpanStyle? = null,
    public val drawStyle: DrawStyle? = null,
) : AnnotatedString.Annotation

Styling configuration that applies at the character level.

Use SpanStyle to configure character-level styles such as text color, font size, font family, background color, and text decorations.

For paragraph-level styling (e.g., alignment, line height), see ParagraphStyle.

Properties

color

Source set: Common
public val color: Color

Color to draw text.

brush

Source set: Common
public val brush: Brush?

Brush to draw text. If not null, overrides color.

alpha

Source set: Common
public val alpha: Float

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

Functions

merge

Source set: Common
public fun merge(other: SpanStyle? = null): SpanStyle

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

other span style's null or inherit properties are replaced with the non-null properties of this span 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 span style is null, returns this span style.

Parameters

other style to merge

plus

Source set: Common
@Stable public operator fun plus(other: SpanStyle): SpanStyle

Plus operator overload that applies a merge.

copy

Source set: Common
@Deprecated(
        "SpanStyle copy constructors that do not take new stable parameters " +
            "like PlatformStyle, DrawStyle are deprecated. Please use the new stable " +
            "copy constructor.",
        level = DeprecationLevel.HIDDEN,
    )
    public fun copy(
        color: Color = this.color,
        fontSize: TextUnit = this.fontSize,
        fontWeight: FontWeight? = this.fontWeight,
        fontStyle: FontStyle? = this.fontStyle,
        fontSynthesis: FontSynthesis? = this.fontSynthesis,
        fontFamily: FontFamily? = this.fontFamily,
        fontFeatureSettings: String? = this.fontFeatureSettings,
        letterSpacing: TextUnit = this.letterSpacing,
        baselineShift: BaselineShift? = this.baselineShift,
        textGeometricTransform: TextGeometricTransform? = this.textGeometricTransform,
        localeList: LocaleList? = this.localeList,
        background: Color = this.background,
        textDecoration: TextDecoration? = this.textDecoration,
        shadow: Shadow? = this.shadow,
    ): SpanStyle

copy

Source set: Common
@Deprecated(
        "SpanStyle copy constructors that do not take new stable parameters " +
            "like PlatformStyle, DrawStyle are deprecated. Please use the new stable " +
            "copy constructor.",
        level = DeprecationLevel.HIDDEN,
    )
    public fun copy(
        color: Color = this.color,
        fontSize: TextUnit = this.fontSize,
        fontWeight: FontWeight? = this.fontWeight,
        fontStyle: FontStyle? = this.fontStyle,
        fontSynthesis: FontSynthesis? = this.fontSynthesis,
        fontFamily: FontFamily? = this.fontFamily,
        fontFeatureSettings: String? = this.fontFeatureSettings,
        letterSpacing: TextUnit = this.letterSpacing,
        baselineShift: BaselineShift? = this.baselineShift,
        textGeometricTransform: TextGeometricTransform? = this.textGeometricTransform,
        localeList: LocaleList? = this.localeList,
        background: Color = this.background,
        textDecoration: TextDecoration? = this.textDecoration,
        shadow: Shadow? = this.shadow,
        platformStyle: PlatformSpanStyle? = this.platformStyle,
    ): SpanStyle

copy

Source set: Common
public fun copy(
        color: Color = this.color,
        fontSize: TextUnit = this.fontSize,
        fontWeight: FontWeight? = this.fontWeight,
        fontStyle: FontStyle? = this.fontStyle,
        fontSynthesis: FontSynthesis? = this.fontSynthesis,
        fontFamily: FontFamily? = this.fontFamily,
        fontFeatureSettings: String? = this.fontFeatureSettings,
        letterSpacing: TextUnit = this.letterSpacing,
        baselineShift: BaselineShift? = this.baselineShift,
        textGeometricTransform: TextGeometricTransform? = this.textGeometricTransform,
        localeList: LocaleList? = this.localeList,
        background: Color = this.background,
        textDecoration: TextDecoration? = this.textDecoration,
        shadow: Shadow? = this.shadow,
        platformStyle: PlatformSpanStyle? = this.platformStyle,
        drawStyle: DrawStyle? = this.drawStyle,
    ): SpanStyle

copy

Source set: Common
public fun copy(
        brush: Brush?,
        alpha: Float = this.alpha,
        fontSize: TextUnit = this.fontSize,
        fontWeight: FontWeight? = this.fontWeight,
        fontStyle: FontStyle? = this.fontStyle,
        fontSynthesis: FontSynthesis? = this.fontSynthesis,
        fontFamily: FontFamily? = this.fontFamily,
        fontFeatureSettings: String? = this.fontFeatureSettings,
        letterSpacing: TextUnit = this.letterSpacing,
        baselineShift: BaselineShift? = this.baselineShift,
        textGeometricTransform: TextGeometricTransform? = this.textGeometricTransform,
        localeList: LocaleList? = this.localeList,
        background: Color = this.background,
        textDecoration: TextDecoration? = this.textDecoration,
        shadow: Shadow? = this.shadow,
        platformStyle: PlatformSpanStyle? = this.platformStyle,
        drawStyle: DrawStyle? = this.drawStyle,
    ): SpanStyle