0Pricing
Jetpack Compose Academy · Lektion

AnnotatedString: Formatierter gemischter Text

Formatieren Sie Bereiche innerhalb eines einzigen Text-Blocks.

AnnotatedString: Formatierter gemischter Text ist eine kostenlose Jetpack Compose Academy-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Jetpack Compose Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Jetpack Compose Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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. 🎉

Häufig gestellte Fragen

Ist die Lektion „AnnotatedString: Formatierter gemischter Text“ kostenlos?

Ja — der vollständige Text von „AnnotatedString: Formatierter gemischter Text“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Jetpack Compose Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Jetpack Compose Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „AnnotatedString: Formatierter gemischter Text“?

Formatieren Sie Bereiche innerhalb eines einzigen Text-Blocks. Du übst Jetpack Compose Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Jetpack Compose Academy zu starten?

Keine Vorkenntnisse erforderlich. Jetpack Compose Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.

Wie lange dauert die Lektion „AnnotatedString: Formatierter gemischter Text“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Jetpack Compose Academy-Lektion Code schreiben und ausführen?

Ja. Jede Jetpack Compose Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Die Text-Composable
  2. Schriftgröße, -stärke und -stil
  3. Farbe, Ausrichtung und Überlauf
  4. AnnotatedString: Formatierter gemischter Text
← Zurück zu Jetpack Compose Academy