کاربران به یک راه آسان برای بازگشت به صفحه اصلی برنامه شما نیاز دارند. برای این کار یک دکمه Up ارائه دهید در نوار برنامه برای همه فعالیت ها به جز فعالیت اصلی. هنگامی که کاربر دکمه Up را انتخاب می کند، برنامه به فعالیت والد هدایت می شود.
این صفحه به شما نشان می دهد که چگونه با استفاده از مولفه Jetpack Navigation، دکمه Up را به نوار برنامه اضافه کنید. برای توضیح دقیق تر، به به روز رسانی اجزای رابط کاربری با NavigationUI مراجعه کنید.
نوار برنامه خود را پیکربندی کنید
نوار برنامه خود را با استفاده از AppBarConfiguration پیکربندی کنید. از AppBarConfiguration ، می توانید نوار برنامه را از مقاصد سطح بالای خود مطلع کنید. اگر کشوی پیمایش پیکربندی شده است، نماد منوی کشو در نوار برنامه در مقاصد سطح بالا نمایش داده می شود. اگر کشوی پیمایش پیکربندی نشده باشد، دکمه پیمایش در مقاصد سطح بالا پنهان می شود.
در هر دو مورد، دکمه Up در تمام مقاصد دیگر نمایش داده می شود. با فشار دادن دکمه بالا navigateUp() فراخوانی می شود.
مثال زیر نحوه پیکربندی نوار برنامه با استفاده از AppBarConfiguration را نشان می دهد:
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Add an Up action\n\nTry the Compose way \nJetpack Compose is the recommended UI toolkit for Android. Learn how to add components in Compose. \n[Navigate from top app bar →](/develop/ui/compose/components/app-bars-navigate) \n\nUsers need an easy way to get back to your app's main screen. To do this, provide an *Up*\nbutton on the app bar\nfor all activities except the main one. When the user selects the Up button, the app navigates to\nthe parent activity.\n\nThis page shows you how to add an Up button to an app bar using the Jetpack Navigation component.\nFor a more detailed explanation, see\n[Update UI components with NavigationUI](/guide/navigation/navigation-ui).\n| **Note:** We recommend using the Jetpack Navigation component to handle your app navigation. This component handles navigating up from the current screen in your app when the user taps the Up button. To learn more, see the documentation for the [Jetpack Navigation component](/guide/navigation).\n\nConfigure your app bar\n----------------------\n\nConfigure your app bar using an\n[AppBarConfiguration](/reference/androidx/navigation/ui/AppBarConfiguration).\nFrom the `AppBarConfiguration`, you can inform the app bar of your top-level\ndestinations. If the navigation drawer is configured, the drawer menu icon\ndisplays on the app\nbar on top-level destinations. If the navigation drawer isn't configured, the navigation button is\nhidden on top-level destinations.\n\nIn both cases, the Up button displays on all other destinations. Pressing the Up button calls\n[navigateUp()](/reference/androidx/navigation/NavController#navigateUp()).\n\nThe following example shows how to configure an app bar using\n`AppBarConfiguration`: \n\n### Kotlin\n\n```kotlin\n override fun onCreate(savedInstanceState: Bundle?) {\n ...\n val navController = findNavController(R.id.nav_host_fragment_activity_main)\n \n val appBarConfiguration = AppBarConfiguration(\n setOf(\n R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications\n )\n )\n binding.myToolbar.setupWithNavController(navController, appBarConfiguration)\n }\n \n```\n\n### Java\n\n```java\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n ...\n NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main);\n\n AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(\n R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)\n .build();\n NavigationUI.setupWithNavController(binding.myToolbar, navController, appBarConfiguration);\n }\n \n```"]]