Contents
How to Move Between Fragments Using the Navigation Component
- Add the dependencies for the navigation component.
- Create the navigation graph resource.
- Add the NavHostFragment to the MainActivity layout.
- Create Actions enabling navigation between Destinations in the Navigation Graph.
Define destination arguments
- In the Navigation editor, click on the destination that receives the argument.
- In the Attributes panel, click Add (+).
- In the Add Argument Link window that appears, enter the argument name, argument type, whether the argument is nullable, and a default value, if needed.
- Click Add.
How do you use the navigation app?
Start or stop navigation
- On your Android phone or tablet, open the Google Maps app .
- Search for a place or tap it on the map.
- In the bottom left, tap Directions.
- Optional: To add additional destinations, go to the top right and tap More.
- Choose one of the following:
Android Jetpack’s Navigation component helps you implement navigation, from simple button clicks to more complex patterns, such as app bars and the navigation drawer. The Navigation component also ensures a consistent and predictable user experience by adhering to an established set of principles.
Close the drawer programmatically.
- Create a Scaffold. To add a drawer to the app, wrap it in a Scaffold widget.
- Add a drawer. Now add a drawer to the Scaffold .
- Populate the drawer with items. Now that you have a Drawer in place, add content to it.
- Close the drawer programmatically.
- Interactive example.
How do I pass props in navigation navigate?
Summary
- navigate and push accept an optional second argument to let you pass parameters to the route you are navigating to.
- You can read the params through route.params inside a screen.
- You can update the screen’s params with navigation.setParams.
- Initial params can be passed via the initialParams prop on Screen.