androidx.navigation.fragment

Classes

FragmentNavigator

Navigator that navigates through fragment transactions.

FragmentNavigatorDestinationBuilder

DSL for constructing a new FragmentNavigator.Destination

NavHostFragment

NavHostFragment provides an area within your layout for self-contained navigation to occur.

Top-level functions summary

FragmentNavigator.Extras
FragmentNavigatorExtras(vararg sharedElements: Pair<View, String>)

Create a new FragmentNavigator.Extras instance with the given shared elements

Extension functions summary

For Fragment
NavController

Find a NavController given a Fragment

NavArgsLazy<Args>

Returns a Lazy delegate to access the Fragment's arguments as an Args instance.

For NavGraphBuilder
Unit

Construct a new FragmentNavigator.Destination

Unit

Construct a new FragmentNavigator.Destination

Top-level functions

FragmentNavigatorExtras

fun FragmentNavigatorExtras(vararg sharedElements: Pair<View, String>): FragmentNavigator.Extras

Create a new FragmentNavigator.Extras instance with the given shared elements

Parameters
sharedElements One or more pairs of View+String names to be passed through to FragmentNavigator.Extras.Builder.addSharedElement.

Extension functions

findNavController

fun Fragment.findNavController(): NavController

Find a NavController given a Fragment

Calling this on a Fragment that is not a NavHostFragment or within a NavHostFragment will result in an IllegalStateException

fragment

inline fun <reified F : Fragment> NavGraphBuilder.fragment(@IdRes id: Int): Unit

Construct a new FragmentNavigator.Destination

fragment

inline fun <reified F : Fragment> NavGraphBuilder.fragment(@IdRes id: Int, builder: FragmentNavigatorDestinationBuilder.() -> Unit): Unit

Construct a new FragmentNavigator.Destination

navArgs

@MainThread inline fun <reified Args : NavArgs> Fragment.navArgs(): NavArgsLazy<Args>

Returns a Lazy delegate to access the Fragment's arguments as an Args instance.

It is strongly recommended that this method only be used when the Fragment is created by androidx.navigation.NavController.navigate with the corresponding androidx.navigation.NavDirections object, which ensures that the required arguments are present.


class MyFragment : Fragment() {
    val args: MyFragmentArgs by navArgs()
}

This property can be accessed only after the Fragment's constructor.