با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
می توانید با استفاده از اقدامات ناوبری بین قطعات ارتباط برقرار کنید. برانگیختن یک عمل ناوبری کاربر را از یک مقصد به مقصد دیگر می برد. این راهنما توضیح می دهد که اقدامات چیست و نشان می دهد که چگونه می توانید آنها را ایجاد و استفاده کنید.
نمای کلی
هر اقدام یک شناسه منحصر به فرد دارد و می تواند شامل ویژگی های اضافی مانند مقصد باشد. مقصد، صفحهای را مشخص میکند که برنامه کاربر را هنگام فعال کردن عمل به آن میبرد. این عمل همچنین می تواند از آرگومان ها برای انتقال داده ها از یک مقصد به مقصد دیگر استفاده کند.
Safe Args: با استفاده از کنشها، میتوانید شناسههای منبع را با عملیات Safe Args-generated جایگزین کنید و ایمنی بیشتری در زمان کامپایل فراهم کنید.
با استفاده از تگ های <action> ، اقدامات را در فایل XML گراف ناوبری خود تعریف کنید. قطعه زیر عملی را اجرا می کند که انتقال از FragmentA به FragmentB را نشان می دهد.
میتوانید از کنشهای جهانی برای پیمایش به مقصدی از هر نقطه استفاده کنید.
برای هر مقصدی در برنامه شما که از طریق بیش از یک مسیر قابل دسترسی است، یک کنش جهانی متناظر را که به آن مقصد هدایت میشود، تعریف کنید.
مثال زیر را در نظر بگیرید. مقصدهای results_winner و game_over هر دو باید به مقصد اصلی باز شوند. اکشن action_pop_out_of_game توانایی انجام این کار را فراهم می کند. action_pop_out_of_game یک اقدام سراسری خارج از هر قطعه خاصی است. این بدان معناست که میتوانید در هر جایی از in_game_nav_graph به آن مراجعه کنید و آن را فراخوانی کنید.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و 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,["# Use Navigation actions and Fragments\n\nYou can build connections between fragments using navigation actions. Evoking a\nnavigation action takes the user from one destination to another. This guide\nexplains what actions are and demonstrates how you can create and use them.\n| **Warning:** The navigation actions API is available only when using the views UI framework.\n\nOverview\n--------\n\nEach action has a unique ID and can contain additional attributes, such as a\ndestination. The destination defines the screen to which the app takes the user\nwhen they trigger the action. The action can also use arguments to carry data\nfrom one destination to another.\n\n- **Safe Args:** Using actions, you can replace resource IDs with [Safe\n Args-generated operations](/guide/navigation/design/actions), providing additional compile-time safety.\n- **Animations:** You can also animate transitions between the destinations. For more information, see [Animate transitions between destinations](/reference/androidx/navigation/Navigation#createNavigateOnClickListener(int)).\n\nExamples\n--------\n\nDefine actions in your navigation graph XML file using the `\u003caction\u003e` tags. The\nfollowing snippet implements an action that represents a transition from\n`FragmentA` to `FragmentB`. \n\n \u003cfragment\n android:id=\"@+id/fragmentA\"\n android:name=\"com.example.FragmentA\"\u003e\n \u003caction\n android:id=\"@+id/action_fragmentA_to_fragmentB\"\n app:destination=\"@id/fragmentB\" /\u003e\n \u003c/fragment\u003e\n\n### Navigate using an action\n\nTo navigate using this action, you call [`NavController.navigate()`](/reference/androidx/navigation/NavController#navigate) and pass\nit the action's `id`: \n\n navController.navigate(R.id.action_fragmentA_to_fragmentB)\n\n| **Important:** For more information about how to use `NavController.navigate()` and its various overloads, see the [Navigate to a\n| destination](/guide/navigation/use-graph/navigate) guide.\n\nGlobal actions\n--------------\n\nYou can use global actions to navigate to a destination from anywhere.\n\nFor any destination in your app that is accessible through more than one path,\ndefine a corresponding global action that navigates to that\ndestination.\n\nConsider the following example. The `results_winner` and `game_over`\ndestinations both need to pop up to the home destination. The\n`action_pop_out_of_game` action provides the ability to do so;\n`action_pop_out_of_game`is a global action outside of any specific fragment.\nThat means you can reference and call it anywhere within the\n`in_game_nav_graph`. \n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cnavigation xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n android:id=\"@+id/in_game_nav_graph\"\n app:startDestination=\"@id/in_game\"\u003e\n\n \u003c!-- Action back to destination which launched into this in_game_nav_graph --\u003e\n \u003caction android:id=\"@+id/action_pop_out_of_game\"\n app:popUpTo=\"@id/in_game_nav_graph\"\n app:popUpToInclusive=\"true\" /\u003e\n\n \u003cfragment\n android:id=\"@+id/in_game\"\n android:name=\"com.example.android.gamemodule.InGame\"\n android:label=\"Game\"\u003e\n \u003caction\n android:id=\"@+id/action_in_game_to_resultsWinner\"\n app:destination=\"@id/results_winner\" /\u003e\n \u003caction\n android:id=\"@+id/action_in_game_to_gameOver\"\n app:destination=\"@id/game_over\" /\u003e\n \u003c/fragment\u003e\n\n \u003cfragment\n android:id=\"@+id/results_winner\"\n android:name=\"com.example.android.gamemodule.ResultsWinner\" /\u003e\n\n \u003cfragment\n android:id=\"@+id/game_over\"\n android:name=\"com.example.android.gamemodule.GameOver\"\n android:label=\"fragment_game_over\"\n tools:layout=\"@layout/fragment_game_over\" /\u003e\n\n \u003c/navigation\u003e"]]