androidx.navigation.ui
Classes
AppBarConfiguration |
Configuration options for |
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 |
Top-level functions summary
Extension functions summary
For android.view.MenuItem | |
Boolean |
Attempt to navigate to the NavDestination associated with this MenuItem. |
For androidx.appcompat.app.AppCompatActivity | |
Unit |
Sets up the ActionBar returned by AppCompatActivity.getSupportActionBar for use with a NavController. |
Unit |
AppCompatActivity.setupActionBarWithNavController(: NavController, : AppBarConfiguration = AppBarConfiguration(navController.graph)) Sets up the ActionBar returned by AppCompatActivity.getSupportActionBar for use with a NavController. |
For androidx.appcompat.widget.Toolbar | |
Unit |
Sets up a Toolbar for use with a NavController. |
Unit |
Toolbar.setupWithNavController(: NavController, : AppBarConfiguration = AppBarConfiguration(navController.graph)) Sets up a Toolbar for use with a NavController. |
For com.google.android.material.appbar.CollapsingToolbarLayout | |
Unit |
CollapsingToolbarLayout.setupWithNavController(: Toolbar, : NavController, : DrawerLayout?) Sets up a CollapsingToolbarLayout and Toolbar for use with a NavController. |
Unit |
CollapsingToolbarLayout.setupWithNavController(: Toolbar, : NavController, : AppBarConfiguration = AppBarConfiguration(navController.graph)) Sets up a CollapsingToolbarLayout and Toolbar for use with a NavController. |
For com.google.android.material.bottomnavigation.BottomNavigationView | |
Unit |
BottomNavigationView.setupWithNavController(: NavController) Sets up a BottomNavigationView for use with a NavController. |
For com.google.android.material.navigation.NavigationView | |
Unit |
NavigationView.setupWithNavController(: NavController) Sets up a NavigationView for use with a NavController. |
For NavController | |
Boolean |
Handles the Up button by delegating its behavior to the given NavController. |
Boolean |
Handles the Up button by delegating its behavior to the given NavController. |
Top-level functions
AppBarConfiguration
inline fun AppBarConfiguration(: NavGraph, : DrawerLayout? = null, noinline : () -> Boolean = { false }): AppBarConfiguration
Configuration options for NavigationUI methods that interact with implementations of the app bar pattern such as android.support.v7.widget.Toolbar, android.support.design.widget.CollapsingToolbarLayout, and android.support.v7.app.ActionBar.
Parameters | |
---|---|
navGraph |
The NavGraph whose start destination should be considered the only top level destination. The Up button will not be displayed when on the start destination of the graph. |
drawerLayout |
The DrawerLayout that should be toggled from the Navigation button. The the Navigation button will show a drawer symbol when it is not being shown as an Up button. |
fallbackOnNavigateUpListener |
Lambda that will be invoked if
androidx.navigation.NavController.navigateUp returns false |
AppBarConfiguration
inline fun AppBarConfiguration(: Menu, : DrawerLayout? = null, noinline : () -> Boolean = { false }): AppBarConfiguration
Configuration options for NavigationUI methods that interact with implementations of the app bar pattern such as android.support.v7.widget.Toolbar, android.support.design.widget.CollapsingToolbarLayout, and android.support.v7.app.ActionBar.
Parameters | |
---|---|
topLevelMenu |
A Menu containing MenuItems corresponding with the destinations considered at the top level of your information hierarchy. The Up button will not be displayed when on these destinations. |
drawerLayout |
The DrawerLayout that should be toggled from the Navigation button. The the Navigation button will show a drawer symbol when it is not being shown as an Up button. |
fallbackOnNavigateUpListener |
Lambda that will be invoked if
androidx.navigation.NavController.navigateUp returns false |
AppBarConfiguration
inline fun AppBarConfiguration(: Set<Int>, : DrawerLayout? = null, noinline : () -> Boolean = { false }): AppBarConfiguration
Configuration options for NavigationUI methods that interact with implementations of the app bar pattern such as android.support.v7.widget.Toolbar, android.support.design.widget.CollapsingToolbarLayout, and android.support.v7.app.ActionBar.
Parameters | |
---|---|
topLevelDestinationIds |
The set of destinations by id considered at the top level of your information hierarchy. The Up button will not be displayed when on these destinations. |
drawerLayout |
The DrawerLayout that should be toggled from the Navigation button. The the Navigation button will show a drawer symbol when it is not being shown as an Up button. |
fallbackOnNavigateUpListener |
Lambda that will be invoked if
androidx.navigation.NavController.navigateUp returns false |
Extension functions
navigateUp
fun NavController.navigateUp(: DrawerLayout?): 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. |
navigateUp
fun NavController.navigateUp(: AppBarConfiguration): Boolean
Handles the Up button by delegating its behavior to the given NavController.
Return | |
---|---|
True if the NavController was able to navigate up. |
onNavDestinationSelected
fun MenuItem.onNavDestinationSelected(: 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.
By default, the back stack will be popped back to the navigation graph's start destination.
Menu items that have android:menuCategory="secondary"
will not pop the back
stack.
Return | |
---|---|
True if the NavController was able to navigate to the destination. |
setupActionBarWithNavController
fun AppCompatActivity.setupActionBarWithNavController(: NavController, : DrawerLayout?): 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 start destination of your navigation graph is considered the only top level
destination. On the start destination of your navigation graph, the ActionBar will show
the drawer icon if the given drawerLayout
is non null. On all other destinations,
the ActionBar will show the Up button.
You are responsible for calling NavController.navigateUp to handle the Navigation button. Typically this is done in AppCompatActivity.onSupportNavigateUp.
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 Navigation button |
setupActionBarWithNavController
fun AppCompatActivity.setupActionBarWithNavController(: NavController, : AppBarConfiguration = AppBarConfiguration(navController.graph)): 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 AppBarConfiguration you provide controls how the Navigation button is displayed.
You are responsible for calling NavController.navigateUp to handle the Navigation button. Typically this is done in AppCompatActivity.onSupportNavigateUp.
Parameters | |
---|---|
navController |
The NavController whose navigation actions will be reflected in the title of the action bar. |
configuration |
Additional configuration options for customizing the behavior of the ActionBar |
setupWithNavController
fun Toolbar.setupWithNavController(: NavController, : DrawerLayout?): Unit
Sets up a Toolbar for use with a NavController.
By calling this method, the title in the Toolbar will automatically be updated when the destination changes (assuming there is a valid label).
The start destination of your navigation graph is considered the only top level
destination. On the start destination of your navigation graph, the Toolbar will show
the drawer icon if the given drawerLayout
is non null. On all other destinations,
the Toolbar will show the Up button.
This method will call NavController.navigateUp when the navigation icon is clicked.
Parameters | |
---|---|
navController |
The NavController whose navigation actions will be reflected in the title of the Toolbar. |
drawerLayout |
The DrawerLayout that should be toggled from the Navigation button |
setupWithNavController
fun Toolbar.setupWithNavController(: NavController, : AppBarConfiguration = AppBarConfiguration(navController.graph)): Unit
Sets up a Toolbar for use with a NavController.
By calling this method, the title in the Toolbar will automatically be updated when the destination changes (assuming there is a valid label).
The AppBarConfiguration you provide controls how the Navigation button is displayed and what action is triggered when the Navigation button is tapped.
This method will call NavController.navigateUp when the navigation icon is clicked.
Parameters | |
---|---|
navController |
The NavController whose navigation actions will be reflected in the title of the Toolbar. |
configuration |
Additional configuration options for customizing the behavior of the Toolbar |
setupWithNavController
fun CollapsingToolbarLayout.setupWithNavController(: Toolbar, : NavController, : DrawerLayout?): Unit
Sets up a CollapsingToolbarLayout and Toolbar for use with a NavController.
By calling this method, the title in the Toolbar will automatically be updated when the destination changes (assuming there is a valid label).
The start destination of your navigation graph is considered the only top level
destination. On the start destination of your navigation graph, the Toolbar will show
the drawer icon if the given drawerLayout
is non null. On all other destinations,
the Toolbar will show the Up button.
This method will call NavController.navigateUp when the Navigation button is clicked.
Parameters | |
---|---|
toolbar |
The Toolbar that should be kept in sync with changes to the NavController. |
navController |
The NavController whose navigation actions will be reflected in the title of the Toolbar. |
drawerLayout |
The DrawerLayout that should be toggled from the Navigation button |
setupWithNavController
fun CollapsingToolbarLayout.setupWithNavController(: Toolbar, : NavController, : AppBarConfiguration = AppBarConfiguration(navController.graph)): Unit
Sets up a CollapsingToolbarLayout and Toolbar for use with a NavController.
By calling this method, the title in the Toolbar will automatically be updated when the destination changes (assuming there is a valid label).
The AppBarConfiguration you provide controls how the Navigation button is displayed and what action is triggered when the Navigation button is tapped.
This method will call NavController.navigateUp when the navigation icon is clicked.
Parameters | |
---|---|
toolbar |
The Toolbar that should be kept in sync with changes to the NavController. |
navController |
The NavController whose navigation actions will be reflected in the title of the Toolbar. |
configuration |
Additional configuration options for customizing the behavior of the Toolbar |
setupWithNavController
fun BottomNavigationView.setupWithNavController(: 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): 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.