Navigation View's Selectors Behave Incorrectly
Solution 1:
I've had a similar problem and looks like the way to solve it is to use android:state_checked
instead of the android:state_selected
in all three selectors (at least that solved it for me).
Solution 2:
You can use setItemTextColor
and setItemIconTintList
for set text color tint and icon color tint to item of NavigationDrawer,
To use this methods add this code to end of onCreateView:
int[][] states = newint[][]{
newint[]{-android.R.attr.state_checked},// unchecked statenewint[]{android.R.attr.state_checked}, // checked state
};
int[] colors = newint[]{
ContextCompat.getColor(this, R.color.colorPrimary),
ContextCompat.getColor(this, R.color.colorPrimaryDark)
};
ColorStateList colorStateList = newColorStateList(states, colors);
navigationView.setItemTextColor(colorStateList);
navigationView.setItemIconTintList(colorStateList);
This code set color to unchecked state and checked state. You can set color to other states.
Color array and state array should be have equals member count. You can select color whatever you want. You can use Color class or like the sample use resource. In this link you can find list of available states developer.android.
Solution 3:
Make sure you are not accessing the menu item from bottom navigation and setting its state to 'checked' twice. To avoid that, use:
mBottomNavigationView.selectedItemId(R.id.your_menu_item_id);
instead of
mBottomNavigationView.menu.getItem(position).setChecked(true);
Post a Comment for "Navigation View's Selectors Behave Incorrectly"