탐색 그래프가 확장되면 이러한 작업은 파싱되고 그래프에 정의된 구성을 사용하여 작업에 상응하는 NavAction 객체가 생성됩니다. 예를 들어, action_b_to_a는 대상 b에서 대상 a로의 이동으로 정의됩니다. 작업에는 애니메이션 및 백 스택에서 모든 대상을 삭제하는 popTo 동작이 포함됩니다. 이러한 모든 설정은 NavOptions로 캡처되고 NavAction에 연결됩니다.
이 NavAction을 팔로우하려면 다음 예와 같이 NavController.navigate()를 사용하여 작업의 ID를 전달합니다.
navController.navigate(R.id.action_b_to_a)
프로그래매틱 방식으로 옵션 적용
이전 예는 탐색 그래프 XML 내에서 NavOptions를 지정하는 방법을 보여줍니다. 그러나 특정 옵션은 빌드 시간에 알 수 없는 제약 조건에 따라 달라질 수 있습니다. 이러한 경우 다음 예와 같이 NavOptions를 프로그래매틱 방식으로 만들고 설정해야 합니다.
Kotlin
findNavController().navigate(R.id.action_fragmentOne_to_fragmentTwo,null,navOptions{// Use the Kotlin DSL for building NavOptionsanim{enter=android.R.animator.fade_inexit=android.R.animator.fade_out}})
이 예에서는 확장된 형태의 navigate()를 사용하며 추가 Bundle 및 NavOptions 인수를 포함합니다. navigate()의 모든 변형에는 NavOptions 인수를 허용하는 확장 버전이 있습니다.
암시적 딥 링크로 이동할 때 프로그래매틱 방식으로 NavOptions를 적용할 수도 있습니다.
Kotlin
findNavController().navigate(deepLinkUri,navOptions{// Use the Kotlin DSL for building NavOptionsanim{enter=android.R.animator.fade_inexit=android.R.animator.fade_out}})
navigate()의 이 변형은 NavOptions 인스턴스뿐만 아니라 암시적 딥 링크의 Uri를 사용합니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","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-27(UTC)"],[],[],null,["# Navigate with options\n\nWhen you define an action in the navigation graph using the Kotlin DSL,\nNavigation generates a corresponding [`NavAction`](/reference/androidx/navigation/NavAction) class, which contains the\nconfigurations defined for that action, including the following:\n\n- **[Destination](/reference/kotlin/androidx/navigation/NavAction#getDestinationId()):** The resource ID of the target destination.\n- **[Default arguments](/reference/kotlin/androidx/navigation/NavAction#getDefaultArguments()):** An `android.os.Bundle` containing default values for the target destination, if supplied.\n- **[Navigation options](/reference/kotlin/androidx/navigation/NavAction#getNavOptions()):** Navigation options, represented as [`NavOptions`](/reference/androidx/navigation/NavOptions). This class contains all of the special configuration for transitioning to and back from the target destination, including animation resource configuration, pop behavior, and whether the destination should be launched in single top mode.\n\nOptions with Compose\n--------------------\n\nBy default, `navigate()` adds your new destination to the back stack. You can\nmodify the behavior of `navigate()` by passing additional navigation options to\nyour `navigate()` call.\n\nYou can create an instance of `NavOptions` using a simple lambda. Pass\n`navigate()` the arguments you might otherwise explicitly pass to the\n`NavOptions.Builder`. Consider the following examples:\n\nFor examples, see the [back stack guide](/guide/navigation/backstack#compose-examples) for examples on how to pass options\nto `navigate()` in context.\n| **Note:** You cannot use [`anim` block](/reference/kotlin/androidx/navigation/NavAction#getDefaultArguments()) with Navigation Compose. There is a [feature request](/reference/kotlin/androidx/navigation/NavAction#getNavOptions()) that tracks Transition Animations in Navigation Compose.\n| **Note:** The user's current location is already in the back stack. It appears in the back stack when the user first navigates to the destination, not when they navigate away.\n\nOptions with XML\n----------------\n\nThe following is an example graph consisting of two screens along with an action\nto navigate from one to the other: \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 xmlns:tools=\"http://schemas.android.com/tools\"\n android:id=\"@+id/nav_graph\"\n app:startDestination=\"@id/a\"\u003e\n\n \u003cfragment android:id=\"@+id/a\"\n android:name=\"com.example.myapplication.FragmentA\"\n android:label=\"a\"\n tools:layout=\"@layout/a\"\u003e\n \u003caction android:id=\"@+id/action_a_to_b\"\n app:destination=\"@id/b\"\n app:enterAnim=\"@anim/nav_default_enter_anim\"\n app:exitAnim=\"@anim/nav_default_exit_anim\"\n app:popEnterAnim=\"@anim/nav_default_pop_enter_anim\"\n app:popExitAnim=\"@anim/nav_default_pop_exit_anim\"/\u003e\n \u003c/fragment\u003e\n\n \u003cfragment android:id=\"@+id/b\"\n android:name=\"com.example.myapplication.FragmentB\"\n android:label=\"b\"\n tools:layout=\"@layout/b\"\u003e\n \u003caction android:id=\"@+id/action_b_to_a\"\n app:destination=\"@id/a\"\n app:enterAnim=\"@anim/nav_default_enter_anim\"\n app:exitAnim=\"@anim/nav_default_exit_anim\"\n app:popEnterAnim=\"@anim/nav_default_pop_enter_anim\"\n app:popExitAnim=\"@anim/nav_default_pop_exit_anim\"\n app:popUpTo=\"@+id/a\"\n app:popUpToInclusive=\"true\"/\u003e\n \u003c/fragment\u003e\n \u003c/navigation\u003e\n\nWhen the navigation graph is inflated, these actions are parsed, and\ncorresponding `NavAction` objects are generated with the configurations defined\nin the graph. For example, `action_b_to_a` is defined as navigating from\ndestination `b` to destination `a`. The action includes animations along with\n`popTo` behavior that removes all destinations from the backstack. All of these\nsettings are captured as `NavOptions` and are attached to the `NavAction`.\n\nTo follow this `NavAction`, use `NavController.navigate()`, passing the ID of\nthe action, as shown in the following example: \n\n navController.navigate(R.id.action_b_to_a)\n\n### Apply options programmatically\n\nThe previous examples show how to specify `NavOptions` within the navigation\ngraph XML. However, specific options can vary depending on constraints that are\nunknown at build time. In such cases, the `NavOptions` must be created and set\nprogrammatically, as shown in the following example: \n\n### Kotlin\n\n findNavController().navigate(\n R.id.action_fragmentOne_to_fragmentTwo,\n null,\n navOptions { // Use the Kotlin DSL for building NavOptions\n anim {\n enter = android.R.animator.fade_in\n exit = android.R.animator.fade_out\n }\n }\n )\n\n### Java\n\n NavController navController = NavHostFragment.findNavController(this);\n navController.navigate(\n R.id.action_fragmentOne_to_fragmentTwo,\n null,\n new NavOptions.Builder()\n .setEnterAnim(android.R.animator.fade_in)\n .setExitAnim(android.R.animator.fade_out)\n .build()\n );\n\nThis example uses an extended form of [`navigate()`](/reference/androidx/navigation/NavController#navigate(int,%20android.os.Bundle,%20androidx.navigation.NavOptions)) and contains additional\n`Bundle` and `NavOptions` arguments. All variants of `navigate()` have extended\nversions that accept a `NavOptions` argument.\n| **Note:** `NavOptions` that are applied programmatically override any and all options that have been set in XML.\n\nYou can also programmatically apply `NavOptions` when navigating to implicit\ndeep links: \n\n### Kotlin\n\n findNavController().navigate(\n deepLinkUri,\n navOptions { // Use the Kotlin DSL for building NavOptions\n anim {\n enter = android.R.animator.fade_in\n exit = android.R.animator.fade_out\n }\n }\n )\n\n### Java\n\n NavController navController = NavHostFragment.findNavController(this);\n navController.navigate(\n deepLinkUri,\n new NavOptions.Builder()\n .setEnterAnim(android.R.animator.fade_in)\n .setExitAnim(android.R.animator.fade_out)\n .build()\n );\n\nThis variant of [`navigate()`](/reference/androidx/navigation/NavController#navigate(android.net.Uri,%20androidx.navigation.NavOptions)) takes a [`Uri`](/reference/android/net/Uri) for the implicit deep\nlink, as well as the `NavOptions` instance."]]