Create a new fragment navigation xml file with id main_nav:
">
xml version="1.0" encoding="utf-8"?>
<navigationxmlns: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/main_nav">
navigation>
Navigate to the activity class xml file and add a new FragmentContainerView Ui view tag and add the property app:navGraph with the navigation file id main_nav, now the navigation controller will adapt and render its data on the FragmentContainerView on runtime :
Add 2 fragment placeholders xml tags in the above navigation tag with these respective Ids and setup a navigation action for each fragment with an id and destination parameters :
A Fragment : A Fragment represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events. Fragments cannot live on their own--they must be hosted by an activity or another fragment.
A FragmentContainerView : is a customized Layout designed specifically for Fragments. It extends FrameLayout, so it can reliably handle Fragment Transactions, and it also has additional features to coordinate with fragment behavior.
Notice : FragmentContainerView will only allow views returned by a Fragment's Fragment.onCreateView. Attempting to add any other view will result in an IllegalStateException.
Animated Tab Bar is an awesome navigation extension that you can use to add cool, animated and fully customizable tab navigation in your apps. The extension provides handy methods and properties to change the behaviour as well as the appearance of the navigation bar.