Changing the background of the BottomNavigationView is easy you can do that by adding background property like this
android:background="@color/colorPrimary"
But we want to change background color on click of each item. You can do this by like this.
Call addOnDestinationChangedListener on navController it gives us changed destination and from that get the id of changed destination based on condition change color of that navigation view
navController.addOnDestinationChangedListener(new NavController.OnDestinationChangedListener() {
@Override
public void onDestinationChanged(@NonNull NavController controller, @NonNull NavDestination destination, @Nullable Bundle arguments) {
NavDestination currentDestination = destination;
if(currentDestination.getId()==R.id.navigation_home)
{
navView.setBackground(getDrawable(R.color.colorBlue));
}else if(currentDestination.getId()==R.id.navigation_dashboard)
{
navView.setBackground(getDrawable(R.color.colorAccent));
}else {
navView.setBackground(getDrawable(R.color.colorPurple));
}
}
});
It will look something like this