public class SpanStyle : 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
fontSize
public val fontSize: TextUnit
Glyph size. If TextUnit.Unspecified, inherits size from parent or default style.
letterSpacing
public val letterSpacing: TextUnit
Amount of space (in SP or EM) to add between letters. If TextUnit.Unspecified, inherits from parent.
fontWeight
public val fontWeight: FontWeight?
Typeface thickness (e.g., bold).
fontFamily
public val fontFamily: FontFamily?
Font family for rendering.
color
public val color: Color
Color to draw text.
brush
public val brush: Brush?
Brush to draw text. If not null, overrides color.
alpha
public val alpha: Float
Opacity of text. This value is either provided along side Brush, or via alpha channel in color.
fontStyle
public val fontStyle: FontStyle?
Typeface variant (e.g., italic).
fontSynthesis
public val fontSynthesis: FontSynthesis?
Font synthesis rules to fallback to bold/italic if the requested style is missing in fontFamily.
fontFeatureSettings
public val fontFeatureSettings: String?
Advanced font features in CSS format (e.g., "smcp" for small caps).
baselineShift
public val baselineShift: BaselineShift?
Vertical shift amount from the baseline (e.g., for superscript or subscript).
textGeometricTransform
public val textGeometricTransform: TextGeometricTransform?
Geometric transformation to apply.
localeList
public val localeList: LocaleList?
Locale list for region-specific glyphs.
background
public val background: Color
Color of background rectangle covering entire line height from start to end.
textDecoration
public val textDecoration: TextDecoration?
Decorations (e.g., underline).
shadow
public val shadow: Shadow?
Shadow effect.
platformStyle
public val platformStyle: PlatformSpanStyle?
Platform-specific parameters.
drawStyle
public val drawStyle: DrawStyle?
Drawing style (fill or stroke).
Functions
merge
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
@Stable public operator fun plus(other: SpanStyle): SpanStyle
Plus operator overload that applies a merge.
copy
@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
@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
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
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