'Cant change material toolbar title from bottomnavigation OnItemSelectedListener
I am trying to change the material toolbar title, on bottom navigation item click. but it is not working, the title is not changing. but outside of the block it works fine
here is my code:
homeBinding.navView.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment fragment = null;
switch (item.getItemId()){
case R.id.home:
homeBinding.mainToolbar.setTitle("Home");
homeBinding.imageTitle.setContentDescription("Home");
fragment = new HomeFragment();
break;
case R.id.project:
homeBinding.mainToolbar.setTitle("Home");
homeBinding.imageTitle.setContentDescription("Project");
fragment = new ProjectsFragment();
break;
case R.id.favorites:
homeBinding.mainToolbar.setTitle("Home");
homeBinding.imageTitle.setContentDescription("Favorites");
fragment = new FavoritesFragment();
break;
case R.id.profile:
homeBinding.mainToolbar.setTitle("Home");
homeBinding.imageTitle.setContentDescription("Profile");
fragment = new ProfileFragment();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.home_fragment_container,fragment).addToBackStack(null).commit();
return true;
}
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
