0Pricing
Jetpack Compose Academy · Lesson

AnnotatedString: Rich Mixed Text

Style spans within a single Text block.

AnnotatedString: Rich Mixed Text is a free Jetpack Compose Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Jetpack Compose Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

One Text, Many Styles

Sometimes one word in a sentence needs to stand out. AnnotatedString lets you style spans inside a single Text composable.

Why Not Two Texts

You could split words into separate Texts, but they would wrap awkwardly. AnnotatedString keeps everything as one flowing, naturally wrapping line.

Build It with buildAnnotatedString

Create rich text using the buildAnnotatedString builder. Inside it you append plain text and styled sections in the order you want them shown.

val s = buildAnnotatedString {
    append("Hello ")
}

Append Plain Text

Use append to add normal characters. Calls stack up in sequence, so the final string reads exactly in the order you appended.

append("Welcome, ")
append("friend")

Style a Span

Wrap part of the text in withStyle and give it a SpanStyle. Everything appended inside that block gets that style applied.

withStyle(SpanStyle(fontWeight = FontWeight.Bold)) {
    append("important")
}

SpanStyle Options

A SpanStyle can set color, fontWeight, fontStyle, fontSize, and more, so each span can look completely different from its neighbors.

SpanStyle(color = Color.Blue,
          fontWeight = FontWeight.Bold)

Render It in Text

Pass your finished AnnotatedString straight to Text, just like a plain string. Compose draws every styled span in place.

Text(text = annotatedGreeting)

Mix Bold and Color

Combine spans freely: a bold red word next to a normal sentence. Each withStyle block only affects the text appended inside it. 🙂

ParagraphStyle for Blocks

For line-level changes like alignment or spacing, use ParagraphStyle instead of SpanStyle. It styles whole paragraphs, not single words.

Tag Clickable Words

You can attach a LinkAnnotation so part of the text becomes tappable, perfect for inline links or a Terms of Service line.

Rich Text, One Element

AnnotatedString gives you mixed styling, links, and emphasis in a single Text. It is how you build natural, expressive copy.

Quick Check

You want one word bold inside a normal sentence in a single Text. What do you use?

Recap

You built rich text with buildAnnotatedString, styling spans via withStyle and SpanStyle. One Text can now hold many looks at once. 🎉

Frequently asked questions

Is the “AnnotatedString: Rich Mixed Text” lesson free?

Yes — the full text of “AnnotatedString: Rich Mixed Text” is free to read here on the web, and the Jetpack Compose Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Jetpack Compose Academy course, upgrade to CoddyKit PRO.

What will I learn in “AnnotatedString: Rich Mixed Text”?

Style spans within a single Text block. You practise Jetpack Compose Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Jetpack Compose Academy?

No prior experience is required. Jetpack Compose Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “AnnotatedString: Rich Mixed Text” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Jetpack Compose Academy lesson?

Yes. Every Jetpack Compose Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The Text Composable
  2. Font Size, Weight & Style
  3. Color, Alignment & Overflow
  4. AnnotatedString: Rich Mixed Text
← Back to Jetpack Compose Academy