Google se compromete a impulsar la igualdad racial para las comunidades afrodescendientes. Obtén información al respecto.

NavHostFragment

open class NavHostFragment : Fragment, NavHost
kotlin.Any
   ↳ androidx.fragment.app.Fragment
   ↳ androidx.navigation.fragment.NavHostFragment

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

NavHostFragment is intended to be used as the content area within a layout resource defining your app's chrome around it, e.g.:

<androidx.drawerlayout.widget.DrawerLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:app="http://schemas.android.com/apk/res-auto"
         android:layout_width="match_parent"
         android:layout_height="match_parent">
     <fragment
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:id="@+id/my_nav_host_fragment"
             android:name="androidx.navigation.fragment.NavHostFragment"
             app:navGraph="@navigation/nav_sample"
             app:defaultNavHost="true" />
     <android.support.design.widget.NavigationView
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
             android:layout_gravity="start"/>
  </androidx.drawerlayout.widget.DrawerLayout>
  

Each NavHostFragment has a NavController that defines valid navigation within the navigation host. This includes the navigation graph as well as navigation state such as current location and back stack that will be saved and restored along with the NavHostFragment itself.

NavHostFragments register their navigation controller at the root of their view subtree such that any descendant can obtain the controller instance through the Navigation helper class's methods such as Navigation#findNavController(View). View event listener implementations such as android.view.View.OnClickListener within navigation destination fragments can use these helpers to navigate based on user interaction without creating a tight coupling to the navigation host.

Summary

Public constructors

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

Public methods
open static NavHostFragment
create(@NavigationRes graphResId: Int)

Create a new NavHostFragment instance with an inflated NavGraph resource.

open static NavHostFragment
create(@NavigationRes graphResId: Int, @Nullable startDestinationArgs: Bundle?)

Create a new NavHostFragment instance with an inflated NavGraph resource.

open static NavController
findNavController(@NonNull fragment: Fragment)

Find a NavController given a local Fragment.

NavController

Returns the navigation controller for this navigation host.

open Unit
onAttach(@NonNull context: Context)

open Unit
onAttachFragment(@NonNull childFragment: Fragment)

open Unit
onCreate(@Nullable savedInstanceState: Bundle?)

open View?
onCreateView(@NonNull inflater: LayoutInflater, @Nullable container: ViewGroup?, @Nullable savedInstanceState: Bundle?)

open Unit

open Unit
onInflate(@NonNull context: Context, @NonNull attrs: AttributeSet, @Nullable savedInstanceState: Bundle?)

open Unit
onPrimaryNavigationFragmentChanged(isPrimaryNavigationFragment: Boolean)

open Unit
onSaveInstanceState(@NonNull outState: Bundle)

open Unit
onViewCreated(@NonNull view: View, @Nullable savedInstanceState: Bundle?)

Protected methods
open Navigator<out FragmentNavigator.Destination!>

Create the FragmentNavigator that this NavHostFragment will use.

open Unit
onCreateNavController(@NonNull navController: NavController)

Callback for when the NavController is created.

Inherited functions