Jetpack Navigation: Getting Started

Aug 10 2021 · Kotlin 1.4, Android 11, Android Studio 4.2.1

Part 1: Set Up Navigation

04. Create a Navigation Graph

Episode complete

Play next episode

About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 03. Add Dependencies Next episode: 05. Add Start Destination & NavHost Interface
Transcript: 04. Create a Navigation Graph

A navigation graph is a blueprint of possible navigation destinations and the actions that link them. In the Project window, right-click on the res directory and select New > Android Resource File.

Type “nav_graph” as File name. Select Resource type as Navigation from drop-down list, and then click OK.

When you add your first navigation graph, Android Studio creates a navigation resource directory within the res directory. This directory contains your navigation graph resource file. Click on nav_graph.xml and switch to Design view.

Expand Hosts section on the left side and Attributes section on the right side. What you now see is the Navigation Editor. It looks empty as you have not added anything to graph yet.

The first section Hosts lists the xml that contains NavHost. The midlde section is the graph editor, it shows visual representation of the graph. The third section is the Attributes section, it lists all attributes of the selected destination OR action.

Now, you are ready to add Destinations and Actions to the Navigation Graph!