androidx.navigation.ui

Classes

NavigationUI

Class which hooks up elements typically in the 'chrome' of your application such as global navigation patterns like a navigation drawer or bottom nav bar with your NavController.

Extension functions summary

For android.support.v7.app.AppCompatActivity
Unit
AppCompatActivity.setupActionBarWithNavController(navController: NavController, drawerLayout: DrawerLayout? = null)

Sets up the ActionBar returned by AppCompatActivity.getSupportActionBar for use with a NavController.

For android.support.design.widget.BottomNavigationView
Unit
BottomNavigationView.setupWithNavController(navController: NavController)

Sets up a BottomNavigationView for use with a NavController.

For android.support.design.widget.NavigationView
Unit
NavigationView.setupWithNavController(navController: NavController)

Sets up a NavigationView for use with a NavController.

For android.support.v4.widget.DrawerLayout
Boolean
DrawerLayout?.navigateUp(navController: NavController)

Handles the Up button by delegating its behavior to the given NavController.

For android.view.MenuItem
Boolean

Attempt to navigate to the NavDestination associated with this MenuItem.

Extension functions

navigateUp

fun DrawerLayout?.navigateUp(navController: NavController): Boolean

Handles the Up button by delegating its behavior to the given NavController.

This is equivalent to calling NavController.navigateUp if the DrawerLayout is null.

Return
True if the NavController was able to navigate up.

onNavDestinationSelected

fun MenuItem.onNavDestinationSelected(navController: NavController): Boolean

Attempt to navigate to the NavDestination associated with this MenuItem.

Importantly, it assumes the menu item id matches a valid action id or destination id to be navigated to.

Return
True if the NavController was able to navigate to the destination.

setupActionBarWithNavController

fun AppCompatActivity.setupActionBarWithNavController(navController: NavController, drawerLayout: DrawerLayout? = null): Unit

Sets up the ActionBar returned by AppCompatActivity.getSupportActionBar for use with a NavController.

By calling this method, the title in the action bar will automatically be updated when the destination changes (assuming there is a valid label).

The action bar will also display the Up button when you are on a non-root destination and the drawer icon when on the root destination, automatically animating between them. Call DrawerLayout.navigateUp to handle the Up button.

Parameters
navController The NavController whose navigation actions will be reflected in the title of the action bar.
drawerLayout The DrawerLayout that should be toggled from the home button

setupWithNavController

fun BottomNavigationView.setupWithNavController(navController: NavController): Unit

Sets up a BottomNavigationView for use with a NavController. This will call android.view.MenuItem.onNavDestinationSelected when a menu item is selected.

The selected item in the NavigationView will automatically be updated when the destination changes.

setupWithNavController

fun NavigationView.setupWithNavController(navController: NavController): Unit

Sets up a NavigationView for use with a NavController. This will call android.view.MenuItem.onNavDestinationSelected when a menu item is selected.

The selected item in the NavigationView will automatically be updated when the destination changes.