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 | |
---|---|
<init>() NavHostFragment provides an area within your layout for self-contained navigation to occur. |
Public methods | |
---|---|
open static NavHostFragment |
Create a new NavHostFragment instance with an inflated |
open static NavHostFragment |
Create a new NavHostFragment instance with an inflated |
open static NavController |
findNavController(@NonNull : Fragment) Find a |
NavController |
Returns the |
open Unit | |
open Unit |
onAttachFragment(@NonNull : Fragment) |
open Unit | |
open View? |
onCreateView(@NonNull : LayoutInflater, @Nullable : ViewGroup?, @Nullable : Bundle?) |
open Unit | |
open Unit |
onInflate(@NonNull : Context, @NonNull : AttributeSet, @Nullable : Bundle?) |
open Unit | |
open Unit |
onSaveInstanceState(@NonNull : Bundle) |
open Unit |
onViewCreated(@NonNull : View, @Nullable : Bundle?) |
Protected methods | |
---|---|
open Navigator<out FragmentNavigator.Destination!> |
Create the FragmentNavigator that this NavHostFragment will use. |
open Unit |
onCreateNavController(@NonNull : NavController) Callback for when the |
Inherited functions | |
---|---|