تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يمكنك السماح بظهور روابط متعددة في سلسلة نصية واحدة لتنفيذ إجراءات مختلفة عند النقر على قسم فرعي من النص.
توافق الإصدار
يتطلّب هذا التنفيذ ضبط الحد الأدنى من إصدار حزمة تطوير البرامج (SDK) لمشروعك على المستوى 21 من واجهة برمجة التطبيقات أو
مستوى أعلى.
التبعيات
عرض روابط متعددة في سلسلة واحدة
تضمِّن هذه المقتطفات روابط متعددة يمكن النقر عليها في سلسلة نصية واحدة:
@ComposablefunAnnotatedStringWithLinkSample(){// Display multiple links in the textText(buildAnnotatedString{append("Go to the ")withLink(LinkAnnotation.Url("https://developer.android.com/",TextLinkStyles(style=SpanStyle(color=Color.Blue)))){append("Android Developers ")}append("website, and check out the")withLink(LinkAnnotation.Url("https://developer.android.com/jetpack/compose",TextLinkStyles(style=SpanStyle(color=Color.Green)))){append("Compose guidance")}append(".")})}
تحدِّد هذه الدالة تنسيق الرابط والنص من خلال تمريرها كوسيطات لدالة
LinkAnnotation.Url() (التي يتم تمريرها كوسيطة لدالة
withLink()). تم تضمين مستمع النقرات في
LinkAnnotation.Url().
تضيف نصًا باستخدام append() في نص الدالة withLink.
تكرار هذه العملية لإضافة مقطع نصي مرتبط آخر
النتائج
الشكل 1. لقطة شاشة لسلسلة نصية واحدة تحتوي على رابطَين مختلفَين
المجموعات التي تتضمّن هذا الدليل
هذا الدليل هو جزء من مجموعات الأدلة السريعة المنظَّمة التي تتناول
أهداف تطوير Android الأوسع نطاقًا:
النص الذي يظهر للمستخدم
يشكّل النص جزءًا مركزيًا من أي واجهة مستخدم. تعرَّف على الطرق المختلفة
التي يمكنك من خلالها عرض النص في تطبيقك لتوفير تجربة رائعة للمستخدم.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-02-22 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-02-22 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Support multiple links in a single string of text\n\n\u003cbr /\u003e\n\nYou can support multiple links in a single string of text to perform different\nactions when clicking a subsection of text.\n\nVersion compatibility\n---------------------\n\nThis implementation requires that your project minSDK be set to API level 21 or\nhigher.\n\n### Dependencies\n\n### Kotlin\n\n\u003cbr /\u003e\n\n```kotlin\n implementation(platform(\"androidx.compose:compose-bom:2025.08.00\"))\n implementation(\"androidx.compose.material3:material3\")\n \n```\n\n\u003cbr /\u003e\n\n### Groovy\n\n\u003cbr /\u003e\n\n```groovy\n implementation platform('androidx.compose:compose-bom:2025.08.00')\n implementation 'androidx.compose.material3:material3'\n \n```\n\n\u003cbr /\u003e\n\nDisplay multiple links in a single string\n-----------------------------------------\n\nThis snippet embeds multiple clickable links into a single string of text:\n\n\n```kotlin\n@Composable\nfun AnnotatedStringWithLinkSample() {\n // Display multiple links in the text\n Text(\n buildAnnotatedString {\n append(\"Go to the \")\n withLink(\n LinkAnnotation.Url(\n \"https://developer.android.com/\",\n TextLinkStyles(style = SpanStyle(color = Color.Blue))\n )\n ) {\n append(\"Android Developers \")\n }\n append(\"website, and check out the\")\n withLink(\n LinkAnnotation.Url(\n \"https://developer.android.com/jetpack/compose\",\n TextLinkStyles(style = SpanStyle(color = Color.Green))\n )\n ) {\n append(\"Compose guidance\")\n }\n append(\".\")\n }\n )\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/text/TextSnippets.kt#L564-L590\n```\n\n\u003cbr /\u003e\n\n### Key points about the code\n\n- Uses the [`buildAnnotatedString`](/reference/kotlin/androidx/compose/ui/text/package-summary#buildAnnotatedString(kotlin.Function1)) function to create an annotated string of text.\n- Specifies the the link and text styling by passing them as arguments of the [`LinkAnnotation.Url()`](/reference/kotlin/androidx/compose/ui/text/LinkAnnotation.Url) function (itself passed as an argument of the [`withLink()`](/reference/kotlin/androidx/compose/ui/text/AnnotatedString.Builder#(androidx.compose.ui.text.AnnotatedString.Builder).withLink(androidx.compose.ui.text.LinkAnnotation,kotlin.Function1)) function). A click listener is built into `LinkAnnotation.Url()`.\n- Adds text using [`append()`](/reference/kotlin/androidx/compose/ui/text/AnnotatedString.Builder#append(kotlin.CharSequence,kotlin.Int,kotlin.Int)) in the body of the `withLink` function.\n- Repeats this process to add another linked text segment.\n\nResults\n-------\n\n**Figure 1.** A screenshot of one text string containing two different links.\n\nCollections that contain this guide\n-----------------------------------\n\nThis guide is part of these curated Quick Guide collections that cover\nbroader Android development goals: \n\n### Display text\n\nText is a central piece of any UI. Find out different ways you can present text in your app to provide a delightful user experience. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/display-text) \n\nHave questions or feedback\n--------------------------\n\nGo to our frequently asked questions page and learn about quick guides or reach out and let us know your thoughts. \n[Go to FAQ](/quick-guides/faq) [Leave feedback](https://issuetracker.google.com/issues/new?component=1573691&template=1993320)"]]