تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
توفّر أشرطة التنقّل الجانبية إمكانية الوصول إلى وجهات في التطبيقات التي تعمل على الأجهزة ذات الشاشات الكبيرة. يجب استخدام أشرطة التنقّل الجانبية في الحالات التالية:
الوجهات الرئيسية التي يجب أن تكون متاحة في أي مكان في التطبيق
من ثلاث إلى سبع وجهات رئيسية
تنسيقات الأجهزة اللوحية أو أجهزة الكمبيوتر
الشكل 1. شريط تنقّل عمودي يتضمّن أربع وجهات وزر إجراء عائم
توضّح لك هذه الصفحة كيفية عرض أشرطة التنقّل في تطبيقك مع الشاشات ذات الصلة والتنقل الأساسي.
مساحة واجهة برمجة التطبيقات
استخدِم الدالة البرمجية القابلة للإنشاء NavigationRail مع الدالة NavigationRailItem لتنفيذ شريط جانبي في تطبيقك. يمثّل NavigationRailItem عنصرًا واحدًا في عمود السكك الحديدية.
تتضمّن NavigationRailItem المَعلمات الرئيسية التالية:
selected: تحدّد هذه السمة ما إذا كان العنصر الحالي في اللوحة مميّزًا بصريًا.
onClick(): دالة lambda مطلوبة تحدّد الإجراء الذي سيتم تنفيذه عندما ينقر المستخدم على عنصر في شريط التطبيقات. وهذا هو المكان الذي يتم فيه عادةً التعامل مع أحداث التنقّل أو تعديل حالة عنصر اللوحة المحدّد أو تحميل المحتوى ذي الصلة.
label: تعرض هذه السمة نصًا ضمن عنصر الشريط الجانبي. اختيارية:
icon: تعرض هذه السمة رمزًا داخل عنصر الرف. اختيارية:
مثال: التنقّل باستخدام القضبان
تنفِّذ المقتطفة البرمجية التالية شريط تنقّل ليتمكّن المستخدمون من التنقّل بين شاشات مختلفة في أحد التطبيقات:
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ 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,["Rails provide access to destinations in apps that run on devices with large\nscreens. You should use navigation rails for:\n\n- Top-level destinations that need to be accessible anywhere in an app\n- Three to seven main destinations\n- Tablet or desktop layouts\n\n**Figure 1.** A navigation rail with four destinations and a floating action button.\n\nThis page shows you how to display rails in your app with related screens and\nbasic navigation.\n\nAPI surface\n\nUse the [`NavigationRail`](/reference/kotlin/androidx/compose/material3/package-summary#NavigationRail(androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,kotlin.Function1,androidx.compose.foundation.layout.WindowInsets,kotlin.Function1)) composable with [`NavigationRailItem`](/reference/kotlin/androidx/compose/material3/package-summary#NavigationRailItem(kotlin.Boolean,kotlin.Function0,kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Function0,kotlin.Boolean,androidx.compose.material3.NavigationRailItemColors,androidx.compose.foundation.interaction.MutableInteractionSource)) to\nimplement a rail in your application. The `NavigationRailItem` represents a\nsingle rail item in the rail column.\n\n`NavigationRailItem` includes the following key parameters:\n\n- `selected`: Determines whether the current rail item is visually highlighted.\n- `onClick()`: A required lambda function that defines the action to be performed when the user clicks on the rail item. This is where you typically handle navigation events, update the selected rail item state, or load corresponding content.\n- `label`: Displays text within the rail item. Optional.\n- `icon`: Displays an icon within the rail item. Optional.\n\nExample: Rail-based navigation\n\nThe following snippet implements a navigation rail so users can navigate between\ndifferent 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 NavigationRailExample(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 NavigationRail(modifier = Modifier.padding(contentPadding)) {\n Destination.entries.forEachIndexed { index, destination -\u003e\n NavigationRailItem(\n selected = selectedDestination == index,\n onClick = {\n navController.navigate(route = destination.route)\n selectedDestination = index\n },\n icon = {\n Icon(\n destination.icon,\n contentDescription = destination.contentDescription\n )\n },\n label = { Text(destination.label) }\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#L153-L180\n```\n\n\u003cbr /\u003e\n\nKey points\n\n- `NavigationRail` displays a vertical column of rail items, with each item 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 currently selected rail item.\n - `startDestination.ordinal` gets the numerical index (position) of the `Destination.SONGS` enum entry.\n- When a rail item is clicked, `navController.navigate(route =\n destination.route)` is called to navigate to the corresponding screen.\n- The `onClick` lambda of the `NavigationRailItem` updates the `selectedDestination` state to visually highlight the clicked rail item.\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.** A navigation rail that contains 3 destinations with associated icons: Songs, Album, and Playlist.\n\nAdditional resources\n\n- [Material 3 - Navigation rail](https://m3.material.io/components/navigation-rail/overview)\n- [Navigation with Compose](/develop/ui/compose/navigation)"]]