Interface

TextStyleScope

Configures layout- and draw-affecting text attributes for BasicText.

Source set: Common
public sealed interface TextStyleScope

Configures layout- and draw-affecting text attributes for BasicText.

Use this scope in the styleProvider lambda parameter of BasicText. State reads performed within this scope are observed during the layout phase, skipping recomposition when invalidated and re-evaluating during measurement (recalculating text layout only when layout-affecting attributes change).

Functions

setTextStyle

Source set: Common
public fun setTextStyle(style: TextStyle)

Sets all text attributes from style.

Overwrites all attributes in this scope with the values from style, resetting attributes that are unspecified or null in style. Call individual setter methods after setTextStyle to override specific attributes.

Parameters

style text style to copy attributes from

setColor

Source set: Common
public fun setColor(color: Color)

Sets the color to apply to the text.

If color is specified (color.isSpecified), this clears any brush and alpha previously set via setBrush, setAlpha, or setTextStyle. If color is Color.Unspecified, any existing brush and alpha are preserved.

setBrush

Source set: Common
public fun setBrush(brush: Brush)

Sets the Brush for painting the text, clearing any color previously set via setColor or setTextStyle (resetting it to Color.Unspecified).

setAlpha

Source set: Common
public fun setAlpha(alpha: Float)

Sets the opacity of the text (0.0 to 1.0) applied when a brush is configured (via setBrush or setTextStyle). Cleared when a specified color is set via setColor or when setTextStyle sets a style without a brush.

setFontSize

Source set: Common
public fun setFontSize(fontSize: TextUnit)

Sets the size of glyphs to use when painting the text (e.g., 16.sp).

setFontWeight

Source set: Common
public fun setFontWeight(fontWeight: FontWeight)

Sets the typeface thickness to use when painting the text (e.g., FontWeight.Bold).

setFontStyle

Source set: Common
public fun setFontStyle(fontStyle: FontStyle)

Sets the typeface variant to use when drawing letters (e.g., FontStyle.Italic).

setFontSynthesis

Source set: Common
public fun setFontSynthesis(fontSynthesis: FontSynthesis)

Sets the font synthesis rules determining if and how bold/italic styles are synthesized when the font family does not natively support them.

setFontFamily

Source set: Common
public fun setFontFamily(fontFamily: FontFamily)

Sets the font family used when rendering text.

setFontFeatureSettings

Source set: Common
public fun setFontFeatureSettings(fontFeatureSettings: String)

Sets advanced typography settings in CSS format (e.g., "smcp" for small caps).

setLetterSpacing

Source set: Common
public fun setLetterSpacing(letterSpacing: TextUnit)

Sets the amount of space to add between letters (in SP or EM).

setBaselineShift

Source set: Common
public fun setBaselineShift(baselineShift: BaselineShift)

Sets the vertical shift amount from the baseline (e.g., BaselineShift.Superscript). If BaselineShift.Unspecified, inherits from parent or default style.

setTextGeometricTransform

Source set: Common
public fun setTextGeometricTransform(textGeometricTransform: TextGeometricTransform)

Sets the geometric transformation to apply to the text.

setLocaleList

Source set: Common
public fun setLocaleList(localeList: LocaleList)

Sets the locale list used to select region-specific glyphs.

setBackground

Source set: Common
public fun setBackground(background: Color)

Sets the background color covering the entire line height from start to end.

setTextDecoration

Source set: Common
public fun setTextDecoration(textDecoration: TextDecoration)

Sets the decorations to paint on the text (e.g., TextDecoration.Underline).

setShadow

Source set: Common
public fun setShadow(shadow: Shadow)

Sets the shadow effect applied to the text.

setDrawStyle

Source set: Common
public fun setDrawStyle(drawStyle: DrawStyle)

Sets the drawing style of the text (fill or stroke).

setTextAlign

Source set: Common
public fun setTextAlign(textAlign: TextAlign)

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

setTextDirection

Source set: Common
public fun setTextDirection(textDirection: TextDirection)

Sets the algorithm used to resolve text direction.

setLineHeight

Source set: Common
public fun setLineHeight(lineHeight: TextUnit)

Sets the line height for the paragraph (e.g., 24.sp).

setTextIndent

Source set: Common
public fun setTextIndent(textIndent: TextIndent)

Sets the paragraph indentation.

setPlatformStyle

Source set: Common
public fun setPlatformStyle(platformStyle: PlatformTextStyle)

Sets platform-specific text styling parameters.

setLineHeightStyle

Source set: Common
public fun setLineHeightStyle(lineHeightStyle: LineHeightStyle)

Sets the line height distribution configuration.

setLineBreak

Source set: Common
public fun setLineBreak(lineBreak: LineBreak)

Sets the line breaking configuration of the paragraph.

setHyphens

Source set: Common
public fun setHyphens(hyphens: Hyphens)

Sets the hyphenation configuration of the paragraph.

setTextMotion

Source set: Common
public fun setTextMotion(textMotion: TextMotion)

Sets the text character placement optimization for animated or static text.

Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: