theme: apple-basic
layout: intro
highlighter: shiki
lineNumbers: true
supportFragmentManager.beginTransaction()
.replace(R.id.frame_layout, TestFragment())
.commit()
Note: We strongly recommend using the Navigation library to manage your app's navigation. The framework follows best practices for working with fragments, the back stack, and the fragment manager. For more information about Navigation, see Get started with the Navigation component and Migrate to the Navigation component.
Navigation graph
Navigation host
Navigation controller
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="androidx.navigation.fragment.NavHostFragment"
app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation"/>
// Fragment
val navController = findNavController()
// Activity
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController = navHostFragment.navController
| Type | app:argType syntax | Support for default values | Handled by routes | Nullable |
|---|---|---|---|---|
| Integer | app:argType="integer" | Yes | Yes | No |
| Float | app:argType="float" | Yes | Yes | No |
| Long | app:argType="long" | Yes - Default values must always end with an 'L' suffix (e.g. "123L"). | Yes | No |
| Boolean | app:argType="boolean" | Yes - "true" or "false" | Yes | No |
| String | app:argType="string" | Yes | Yes | Yes |
| Resource Reference | app:argType="reference" | Yes - Default values must be in the form of "@resourceType/resourceName" (e.g. "@style/myCustomStyle") or "0" | Yes | No |
| Custom Parcelable | app:argType=<type>, where <type> is the fully-qualified class name of the Parcelable |
Supports a default value of "@null". Does not support other default values. | No | Yes |
| Custom Serializable | app:argType=<type>, where <type> is the fully-qualified class name of the Serializable |
Supports a default value of "@null". Does not support other default values. | No | Yes |
| Custom Enum | app:argType=<type>, where <type> is the fully-qualified name of the enum |
Yes - Default values must match the unqualified name (e.g. "SUCCESS" to match MyEnum.SUCCESS). | No | No |
action이 시작되는 대상의 이름에 Directions라는 접미어가 붙은 클래스argument를 전달하는데 사용한 action의 이름과 동일한 이름의 클래스Args라는 접미어가 붙은 클래스override fun onClick(v: View) {
val amountTv: EditText = view!!.findViewById(R.id.editTextAmount)
val amount = amountTv.text.toString().toInt()
val action = SpecifyAmountFragmentDirections.confirmationAction(amount)
v.findNavController().navigate(action)
}