change activity main drawer items text color programmatically android code example
Example: change activity main drawer items text color programmatically android
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
int[][] state = new int[][] {
new int[] {-android.R.attr.state_enabled},
new int[] {android.R.attr.state_enabled},
new int[] {-android.R.attr.state_checked},
new int[] { android.R.attr.state_pressed}
};
int[] color = new int[] {
Color.WHITE,
Color.WHITE,
Color.WHITE,
Color.WHITE
};
ColorStateList colorStateList1 = new ColorStateList(state, color);
int[][] states = new int[][] {
new int[] {-android.R.attr.state_enabled},
new int[] {android.R.attr.state_enabled},
new int[] {-android.R.attr.state_checked},
new int[] { android.R.attr.state_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);