NavigationUI
class NavigationUI
kotlin.Any | |
↳ | androidx.navigation.ui.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
.
Summary
Public methods | |
---|---|
static Boolean |
navigateUp(@NonNull : NavController, @Nullable : Openable?) Handles the Up button by delegating its behavior to the given NavController. |
static Boolean |
navigateUp(@NonNull : NavController, @NonNull : AppBarConfiguration) Handles the Up button by delegating its behavior to the given NavController. |
static Boolean |
onNavDestinationSelected(@NonNull : MenuItem, @NonNull : NavController) Attempt to navigate to the |
static Unit |
setupActionBarWithNavController(@NonNull : AppCompatActivity, @NonNull : NavController) Sets up the ActionBar returned by |
static Unit |
setupActionBarWithNavController(@NonNull : AppCompatActivity, @NonNull : NavController, @Nullable : Openable?) Sets up the ActionBar returned by |
static Unit |
setupActionBarWithNavController(@NonNull : AppCompatActivity, @NonNull : NavController, @NonNull : AppBarConfiguration) Sets up the ActionBar returned by |
static Unit |
setupWithNavController(@NonNull : Toolbar, @NonNull : NavController) Sets up a |
static Unit |
setupWithNavController(@NonNull : Toolbar, @NonNull : NavController, @Nullable : Openable?) Sets up a |
static Unit |
setupWithNavController(@NonNull : Toolbar, @NonNull : NavController, @NonNull : AppBarConfiguration) Sets up a |
static Unit |
setupWithNavController(@NonNull : CollapsingToolbarLayout, @NonNull : Toolbar, @NonNull : NavController) Sets up a |
static Unit |
setupWithNavController(@NonNull : CollapsingToolbarLayout, @NonNull : Toolbar, @NonNull : NavController, @Nullable : Openable?) Sets up a |
static Unit |
setupWithNavController(@NonNull : CollapsingToolbarLayout, @NonNull : Toolbar, @NonNull : NavController, @NonNull : AppBarConfiguration) Sets up a |
static Unit |
setupWithNavController(@NonNull : NavigationView, @NonNull : NavController) Sets up a |
static Unit |
setupWithNavController(@NonNull : BottomNavigationView, @NonNull : NavController) Sets up a |
Public methods
navigateUp
static fun navigateUp(
@NonNull : NavController,
@Nullable : Openable?
): Boolean
Handles the Up button by delegating its behavior to the given NavController. This should generally be called from AppCompatActivity#onSupportNavigateUp()
.
If you do not have a Openable
layout, you should call NavController#navigateUp()
directly.
Parameters | |
---|---|
navController |
NavController: The NavController that hosts your content. |
openableLayout |
Openable?: The Openable layout that should be opened if you are on the topmost level of the app. |
Return | |
---|---|
Boolean |
True if the NavController was able to navigate up. |
navigateUp
static fun navigateUp(
@NonNull : NavController,
@NonNull : AppBarConfiguration
): Boolean
Handles the Up button by delegating its behavior to the given NavController. This is an alternative to using NavController#navigateUp()
directly when the given AppBarConfiguration
needs to be considered when determining what should happen when the Up button is pressed.
In cases where no Up action is available, the AppBarConfiguration#getFallbackOnNavigateUpListener()
will be called to provide additional control.
Parameters | |
---|---|
navController |
NavController: The NavController that hosts your content. |
configuration |
AppBarConfiguration: Additional configuration options for determining what should happen when the Up button is pressed. |
Return | |
---|---|
Boolean |
True if the NavController was able to navigate up. |
onNavDestinationSelected
static fun onNavDestinationSelected(
@NonNull : MenuItem,
@NonNull : NavController
): Boolean
Attempt to navigate to the NavDestination
associated with the given MenuItem. This MenuItem should have been added via one of the helper methods in this class.
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.
Parameters | |
---|---|
item |
MenuItem: The selected MenuItem. |
navController |
NavController: The NavController that hosts the destination. |
Return | |
---|---|
Boolean |
True if the NavController was able to navigate to the destination associated with the given MenuItem. |