I know we can set the bottom navigation selection color from XML in this way
But I want to know how we can change it programmatically from my Activity?
This is what I tried in Activity's OnNavigationItemSelectedListener
.
item.getIcon().setTint(ContextCompat.getColor(context, R.color.colorBrown));
Also tried to change tint list like this:
item.setIconTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.colorPrimaryBlue)));
Here is the complete snippet of my code:
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= item -> {
switch (item.getItemId()) {
case R.id.navigationTask:
item.getIcon().setTint(ContextCompat.getColor(context, R.color.colorBrown));
fragment = new MyTaskFragment();
break;
case R.id.navigationProfile:
item.setIconTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.colorPrimaryBlue)));
fragment = new ProfileFragment();
break;
case R.id.navigationRequest:
fragment = new RequestListFragment();
break;
case R.id.navigationMore:
fragment = new MoreFragment();
break;
}
loadFragment(fragment);
return true;
};
but it's not working for me. Any ideas or reference link on how to change this programmatically will be helpful for me.
Note: I want to change only the selected item's icon and text tint color. Not the entire items in the bottom navigation.
Thanks in advance.