[null,null,["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Global actions\n\nYou can use a *global action* to create a common action that multiple\ndestinations can use. For example, you might want buttons in\ndifferent destinations to navigate to the same main app screen.\n\nA global action is represented in the Navigation Editor by a small arrow that\npoints to the associated destination, as shown in figure 1.\n**Figure 1.** A global action that leads to a nested graph.\n\nCreate a global action\n----------------------\n\nTo create a global action, do the following:\n\n1. From the **Graph Editor**, click on a destination to highlight it.\n2. Right-click on the destination to display the context menu.\n3. Select **Add Action \\\u003e Global** . An arrow () appears to the left of the destination.\n4. Click the **Text** tab to navigate to the XML text view. The XML for the\n global action looks similar to the following:\n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cnavigation xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n xmlns:tools=\"http://schemas.android.com/tools\"\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:id=\"@+id/main_nav\"\n app:startDestination=\"@id/mainFragment\"\u003e\n\n ...\n\n \u003caction android:id=\"@+id/action_global_mainFragment\"\n app:destination=\"@id/mainFragment\"/\u003e\n\n \u003c/navigation\u003e\n\nUse a global action\n-------------------\n\nTo use a global action in your code, pass the resource ID of the global action\nto the [`navigate()`](/reference/androidx/navigation/NavController#navigate(int))\nmethod for each UI element, as shown in the following example: \n\n### Kotlin\n\n```kotlin\nviewTransactionButton.setOnClickListener { view -\u003e\n view.findNavController().navigate(R.id.action_global_mainFragment)\n}\n```\n\n### Java\n\n```java\nviewTransactionsButton.setOnClickListener(new View.OnClickListener() {\n @Override\n public void onClick(View view) {\n Navigation.findNavController(view).navigate(R.id.action_global_mainFragment);\n }\n});\n```\n\nUse Safe Args with a global action\n----------------------------------\n\nFor information on using Safe Args with global actions, see\n[Pass data between destinations](/topic/libraries/architecture/navigation/navigation-pass-data#safe-args-global).\n\nAdditional resources\n--------------------\n\nTo learn more about navigation, consult the following\nadditional resources.\n\n### Codelabs\n\n- [Navigation Codelab](https://codelabs.developers.google.com/codelabs/android-navigation/index.html?index=..%2F..%2Findex#0)\n\n### Videos\n\n- [Android Jetpack:\n manage UI navigation with Navigation Controller (Google I/O '18)](https://www.youtube.com/watch?v=8GCXtCjtg40)"]]