0Pricing
Jetpack Compose Academy · درس

‏AnnotatedString: نص منسق مختلط

نسّق المقاطع داخل كتلة Text واحدة

‏AnnotatedString: نص منسق مختلط درس مجاني في Jetpack Compose Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Jetpack Compose Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

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

الأسئلة الشائعة

هل درس «‏AnnotatedString: نص منسق مختلط» مجاني؟

نعم — نص درس «‏AnnotatedString: نص منسق مختلط» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Jetpack Compose Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.

ماذا ستتعلم في «‏AnnotatedString: نص منسق مختلط»؟

نسّق المقاطع داخل كتلة Text واحدة تتمرن على Jetpack Compose Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Jetpack Compose Academy؟

لا تُشترط خبرة سابقة. Jetpack Compose Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «‏AnnotatedString: نص منسق مختلط»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Jetpack Compose Academy هذا؟

نعم. كل درس في Jetpack Compose Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. ‏Composable النص
  2. حجم الخط ووزنه ونمطه
  3. اللون والمحاذاة وتجاوز المساحة
  4. ‏AnnotatedString: نص منسق مختلط
← العودة إلى Jetpack Compose Academy