[null,null,["最后更新时间 (UTC):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"]]