Issue
I want to change the home up indicator but it doesn't work when using navigation component
I tried the solution from here and didn't work how to change toolbar icon (hamburger icon) when using navigation drawer with jetpack navigation component
My Code
setSupportActionBar(binding.toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.myTeamFragment,
R.id.myTasksFragment, R.id.meetingsFragment, R.id.freeTimeFragment, R.id.dashboardFilterFragment)
.setOpenableLayout(binding.getRoot())
.build();
NavigationUI.setupWithNavController(binding.toolbar, getNavController(), appBarConfiguration);
then as Solution Mentioned
ActionBar actionBar = getSupportActionBar();
getNavController().addOnDestinationChangedListener((controller, destination, arguments) -> {
if (destination.getId() == R.id.dest0
|| destination.getId() == R.id.dest1
|| destination.getId() == R.id.dest2
|| destination.getId() == R.id.dest3
|| destination.getId() == R.id.dest4){
actionBar.setHomeAsUpIndicator(R.drawable.ic_hambergur_menu);
} else {
actionBar.setHomeAsUpIndicator(R.drawable.ic_hambergure_back);
}
});
Solution
You are using a setup with a Toolbar
NavigationUI.setupWithNavController(binding.toolbar, getNavController(), appBarConfiguration);
Then use the Toolbar API instead of ActionBar API:
navController.addOnDestinationChangedListener { controller, destination, arguments ->
if (destination.id == R.id.nav_home){
toolbar.setNavigationIcon(R.drawable.xxxx)
}
}
Answered By - Gabriele Mariotti
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.