تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تتيح لك علامات التبويب تنظيم مجموعات من المحتوى ذي الصلة. هناك نوعان من علامات التبويب:
علامات التبويب الأساسية: يتم وضعها في أعلى جزء المحتوى أسفل شريط التطبيق العلوي.
تعرض هذه الروابط وجهات المحتوى الرئيسية، ويجب استخدامها عندما تكون هناك مجموعة واحدة فقط من علامات التبويب.
علامات التبويب الثانوية: تُستخدَم ضمن مساحة المحتوى لزيادة الفصل بين المحتوى ذي الصلة وإنشاء تسلسل هرمي. وتكون ضرورية عندما تتطلّب الشاشة أكثر من مستوى واحد من علامات التبويب.
الشكل 1. علامات التبويب الأساسية (1) وعلامات التبويب الثانوية (2)
توضّح هذه الصفحة كيفية عرض علامات التبويب الأساسية في تطبيقك مع الشاشات ذات الصلة وأدوات التنقّل الأساسية.
مساحة واجهة برمجة التطبيقات
استخدِم عناصر Tab وPrimaryTabRow وSecondaryTabRow القابلة للإنشاء
لتنفيذ علامات التبويب. يمثّل العنصر القابل للإنشاء Tab علامة تبويب فردية ضمن الصف، ويُستخدَم عادةً داخل PrimaryTabRow (لعلامات تبويب المؤشر الأساسي) أو SecondaryTabRow (لعلامات تبويب المؤشر الثانوي).
تتضمّن Tab المَعلمات الرئيسية التالية:
selected: تحدّد ما إذا كان يتم تمييز علامة التبويب الحالية بصريًا.
onClick(): دالة lambda مطلوبة تحدّد الإجراء الذي سيتم تنفيذه عندما ينقر المستخدم على علامة التبويب. وهذا هو المكان الذي تتعامل فيه عادةً مع أحداث التنقّل أو تعدّل حالة علامة التبويب المحدّدة أو تحمّل المحتوى ذي الصلة.
text: لعرض النص داخل علامة التبويب اختيارية:
icon: يعرض رمزًا داخل علامة التبويب. اختيارية:
enabled: تتحكّم هذه السمة في ما إذا كانت علامة التبويب مفعّلة ويمكن التفاعل معها. إذا تم ضبطها على "خطأ"، ستظهر علامة التبويب في حالة غير مفعّلة ولن تستجيب للنقرات.
مثال: التنقّل المستند إلى علامات التبويب
تعرض القصاصة البرمجية التالية شريط تنقّل علويًا يتضمّن علامات تبويب للتنقّل بين الشاشات المختلفة في أحد التطبيقات:
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["Tabs allow you to organize groups of related content. There are two types of\ntabs:\n\n- **Primary tabs**: Placed at the top of the content pane under a top app bar. They display the main content destinations, and should be used when just one set of tabs are needed.\n- **Secondary tabs**: Used within a content area to further separate related content and establish hierarchy. They are necessary when a screen requires more than one level of tabs.\n\n**Figure 1.** Primary tabs (1) and secondary tabs (2).\n\nThis page shows how to display primary tabs in your app with related screens and\nbasic navigation.\n\nAPI surface\n\nUse the [`Tab`](/reference/kotlin/androidx/compose/material3/package-summary#Tab(kotlin.Boolean,kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Function0,kotlin.Function0,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.foundation.interaction.MutableInteractionSource)), [`PrimaryTabRow`](/reference/kotlin/androidx/compose/material3/package-summary#PrimaryTabRow(kotlin.Int,androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,kotlin.Function1,kotlin.Function0,kotlin.Function0)), and [`SecondaryTabRow`](/reference/kotlin/androidx/compose/material3/package-summary#SecondaryTabRow(kotlin.Int,androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,kotlin.Function1,kotlin.Function0,kotlin.Function0)) composables\nto implement tabs. The `Tab` composable represents an individual tab within the\nrow, and is typically used inside of a `PrimaryTabRow` (for primary indicator\ntabs) or `SecondaryTabRow` (for secondary indicator tabs).\n\n`Tab` includes the following key parameters:\n\n- `selected`: Determines whether the current tab is visually highlighted.\n- `onClick()`: A required lambda function that defines the action to be performed when the user clicks on the tab. This is where you typically handle navigation events, update the selected tab state, or load corresponding content.\n- `text`: Displays text within the tab. Optional.\n- `icon`: Displays an icon within the tab. Optional.\n- `enabled`: Controls whether the tab is enabled and can be interacted with. If set to false, the tab appears in a disabled state and won't respond to clicks.\n\nExample: Tab-based navigation\n\nThe following snippet implements a top navigation bar with tabs to navigate\nbetween different screens in an app:\n| **Note:** The [full source code](https://github.com/android/snippets/blob/main/compose/snippets/src/main/java/com/example/compose/snippets/components/Navigation.kt) includes the code that establishes the basic navigation structure for the following example.\n\n\n```kotlin\n@Composable\nfun NavigationTabExample(modifier: Modifier = Modifier) {\n val navController = rememberNavController()\n val startDestination = Destination.SONGS\n var selectedDestination by rememberSaveable { mutableIntStateOf(startDestination.ordinal) }\n\n Scaffold(modifier = modifier) { contentPadding -\u003e\n PrimaryTabRow(selectedTabIndex = selectedDestination, modifier = Modifier.padding(contentPadding)) {\n Destination.entries.forEachIndexed { index, destination -\u003e\n Tab(\n selected = selectedDestination == index,\n onClick = {\n navController.navigate(route = destination.route)\n selectedDestination = index\n },\n text = {\n Text(\n text = destination.label,\n maxLines = 2,\n overflow = TextOverflow.Ellipsis\n )\n }\n )\n }\n }\n AppNavHost(navController, startDestination)\n }\n}https://github.com/android/snippets/blob/f95ab59fad80aeaf5d6a90bab8a01a126f20f44e/compose/snippets/src/main/java/com/example/compose/snippets/components/Navigation.kt#L186-L213\n```\n\n\u003cbr /\u003e\n\nKey points\n\n- `PrimaryTabRow` displays a horizontal row of tabs, with each tab corresponding to a `Destination`.\n- `val navController = rememberNavController()` creates and remembers an instance of [`NavHostController`](/reference/androidx/navigation/NavHostController), which manages the navigation within a [`NavHost`](/reference/androidx/navigation/NavHost).\n- `var selectedDestination by rememberSaveable {\n mutableIntStateOf(startDestination.ordinal) }` manages the state of the selected tab.\n - `startDestination.ordinal` gets the numerical index (position) of the `Destination.SONGS` enum entry.\n- When you click a tab, the `onClick` lambda calls `navController.navigate(route = destination.route)` to navigate to the corresponding screen.\n- The `onClick` lambda of the `Tab` updates the `selectedDestination` state to visually highlight the clicked tab.\n- It calls the `AppNavHost` composable, passing the `navController` and `startDestination`, to display the actual content of the selected screen.\n\nResult\n\nThe following image shows the result of the previous snippet:\n**Figure 2.** 3 tabs--- Songs, Album, and Playlist--- arranged horizontally.\n\nAdditional resources\n\n- [Material 3 - Tabs](https://m3.material.io/components/tabs/guidelines)\n- [Navigation with Compose](/develop/ui/compose/navigation)"]]