Issue
With jetpack navigation, single activity with multiple fragments. After navigating from the main fragment to another fragment via the action defined in the navigation graph, the hamburger menu icon stays the same, it did not change to a back arrow button.
How to change this hamburger menu icon to a back arrow button? when clicked, it should go back to the main fragment.
Creating a new project in Android Studio and choose Navigation Drawer Activity as the template will set up the single activity with 3 fragments described above.
Solution
I had it set up with multiple fragments in the AppBarConfiguration.
appBarConfiguration = AppBarConfiguration(
setOf(
R.id.nav_main, R.id.nav_detail
), drawerLayout
)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
Since the detail fragment was set up in the AppBarConfiguration, that's why when navigated to the detail fragment from the main fragment, the hamburger menu icon stayed the same because the detail fragment was set up to be one of the drawerlayout.
After removing the R.id.nav_detail from the AppBarConfiguration, then navigate to the detail fragment, the hamburger menu icon will automatically changes to a back arrow icon with the DrawerArrowDrawable animation.
appBarConfiguration = AppBarConfiguration(
setOf(
R.id.nav_main
), drawerLayout
)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
Answered By - s-hunter
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.