You need to initialize the colors you want to use using the
ColorStateList object.
After setting up the colors for each state you set the navitaionView
itemTextColor (navigation.setItemTextColor(yourCustomColorStateList);
This is where I got the answer
Here is another related Stackoverflow questions
Official Android documentation of all the available kind of state
example:
Use this inside your onCreate method of your main class just set the colors for the state appropriately use this official developer documentation for the list of states
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
/**
* start of code configuration for color of text of your Navigation Drawer / Menu based on state
*/
int[][] state = new int[][] {
new int[] {-android.R.attr.state_enabled}, // disabled
new int[] {android.R.attr.state_enabled}, // enabled
new int[] {-android.R.attr.state_checked}, // unchecked
new int[] { android.R.attr.state_pressed} // pressed
};
int[] color = new int[] {
Color.WHITE,
Color.WHITE,
Color.WHITE,
Color.WHITE
};
ColorStateList colorStateList1 = new ColorStateList(state, color);
// FOR NAVIGATION VIEW ITEM ICON COLOR
int[][] states = new int[][] {
new int[] {-android.R.attr.state_enabled}, // disabled
new int[] {android.R.attr.state_enabled}, // enabled
new int[] {-android.R.attr.state_checked}, // unchecked
new int[] { android.R.attr.state_pressed} // pressed
};
int[] colors = new int[] {
Color.WHITE,
Color.WHITE,
Color.WHITE,
Color.WHITE
};
ColorStateList colorStateList2 = new ColorStateList(states, colors);
navigationView.setItemTextColor(colorStateList1);
navigationView.setItemIconTintList(colorStateList2);
/**
* end of code configuration for color of text of your Navigation Drawer / Menu based on state
*/