0Pricing
Jetpack Compose Academy · Leçon

AnnotatedString : texte enrichi mixte

Appliquez des styles à des portions d’un même bloc Text.

AnnotatedString : texte enrichi mixte est une leçon Jetpack Compose Academy gratuite sur CoddyKit. Ceci est la leçon 4 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Jetpack Compose Academy, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Jetpack Compose Academy comprend 4 leçons au total.

Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.

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

Questions Fréquemment Posées

La leçon « AnnotatedString : texte enrichi mixte » est-elle gratuite ?

Oui — le texte complet de « AnnotatedString : texte enrichi mixte » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Jetpack Compose Academy, passe à CoddyKit PRO. Le cours Jetpack Compose Academy comprend 4 leçons au total.

Qu'est-ce que j'apprendrai dans « AnnotatedString : texte enrichi mixte » ?

Appliquez des styles à des portions d’un même bloc Text. Tu pratiques Jetpack Compose Academy avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.

Dois-je avoir de l'expérience pour commencer Jetpack Compose Academy ?

Aucune expérience préalable n'est requise. Jetpack Compose Academy sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 4 sur 4.

Combien de temps prend la leçon « AnnotatedString : texte enrichi mixte » ?

La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.

Peux-tu écrire et exécuter du code dans cette leçon Jetpack Compose Academy ?

Oui. Chaque leçon Jetpack Compose Academy inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.

Toutes les leçons de ce cours

  1. Le Composable Text
  2. Taille, épaisseur et style de police
  3. Couleur, alignement et débordement
  4. AnnotatedString : texte enrichi mixte
← Retour à Jetpack Compose Academy