Answer the question
In order to leave comments, you need to log in
How to overload navHostFragment with navigation component?
There is an application consisting of two fragments.
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/app_navigation"
app:startDestination="@id/mediaFragment">
<fragment
android:id="@+id/mediaFragment"
android:name="com.nasa.app.ui.media_preview.PreviewMediaFragment"
android:label="fragment_media"
tools:layout="@layout/fragment_media_preview" >
<action
android:id="@+id/action_mediaFragment_to_detailMediaFragment"
app:destination="@id/detailMediaFragment" />
</fragment>
<fragment
android:id="@+id/detailMediaFragment"
android:name="com.nasa.app.ui.media_detail.DetailMediaFragment"
android:label="DetailMediaFragment" >
<argument
android:name="nasaId"
app:argType="string" />
<argument
android:name="contentType"
app:argType="com.nasa.app.data.model.ContentType" />
</fragment>
</navigation>
Answer the question
In order to leave comments, you need to log in
val navController = findNavController(R.id.nav_host_fragment)
val navHostFragment =supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val inflater = navHostFragment.navController.navInflater
val graph = inflater.inflate(R.navigation.app_navigation)
graph.startDestination = R.id.mediaFragment
navController.graph = graph
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question