I have a Bottom Navigation Bar in Android with 4 icons. At the moment, when I click on an icon it gets highlighted (change of color) until another button is pressed on the Bottom Navigation Bar. While this is good for 3 of the 4 icons, I also have a "Back" button where this should not be the case. So if the Back button is pressed, it should either not be highlited at all, or it should just be highlighted for a very short period of time. Can you tell me how to do this in the Java code?
Here is the code that defines what happens if a button is pressed on the Botton Navigation Bar inside the onCreate
method of the main acticity:
binding.bottomNavigation.setOnNavigationItemSelectedListener(
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
if (item.getItemId()== R.id.BottomNavigation_Back) {
item.setChecked(false);
navController.navigateUp();
}
if (item.getItemId()== R.id.BottomNavigation_Language) {
navController.navigate(R.id.FR_LanguageSelection);
}
if (item.getItemId()== R.id.BottomNavigation_Info) {
navController.navigate(R.id.FR_Info);
}
if (item.getItemId()== R.id.BottomNavigation_Menu) {
navController.navigate(R.id.FR_Menu);
}
return true;
}
});
The relevant chase is the first one if (item.getItemId()== R.id.BottomNavigation_Back)
. I tried to use item.setChecked(false);
but this does not work (as you can see in the screenshot). The Back Icon is still highlighted until another button is pressed. Any idea how to do this?
Reminder: Does anybody have an idea how to do this or why the command item.setChecked(false);
does not work? Strangely when using item.setChecked(true);
the behaviour is exactly the same. Is there a way how to disable the highlight from this specific button after is has been pressed?