Navigation Menus

Learn to implement a bottom navigation bar to navigate across application destinations.

The navigation component helps users navigate through different activities (GUIs) or fragments in an application through simple button clicks or through app bars like the BottomNavigationBar or the NavigationDrawer.

It simplifies the process of constructing and linking different destinations by removing boilerplate code because a developer will find it easier to use a graph than the conventional method of using intents.

Let’s create a navigation graph.

Create a navigation graph

Add dependencies

We will add the necessary dependencies and plugins to our module-level gradle file if they’re not there already.

Press + to interact
// Navigation Components
implementation "androidx.navigation:navigation-fragment-ktx:2.4.2"
implementation "androidx.navigation:navigation-ui-ktx:2.4.2"

Add the following plugin if it’s not added already.

Press + to interact
apply plugin: 'androidx.navigation.safeargs'

To avoid errors when importing these dependencies in the classes, ensure that gradle has successfully synced the newly added dependencies.

Create a navigation graph ...