Hooking Navigation Components
Explore how to integrate navigation components in Android development using Kotlin. Learn to add a NavHostFragment and BottomNavigationView to your layouts, connect them in your activity with ViewBinding, and enable seamless screen transitions via the navigation controller.
We'll cover the following...
Adding navigation components to the news activity
We’ll add a NavHost and a BottomNavigationView to activity_news.xml.
NavHost is a container that hosts fragment destinations as they are swapped from one fragment to the next.
Let’s start with the
FragmentContainerView. It will be inside a frame layout nested inside a ConstraintLayout.
-
android:name="androidx.navigation.fragment.NavHostFragment":This defines the class name of ourNavHost. -
app:navGraph="@navigation/news_nav_graph": This references the location of thenavGraph,which is located inside the foldernavigationwith the filenamenews_nav_graph. -
app:defaultNavHost="true": This ensures ...