I am a beginner in Android Development. Using android\'s default Navigation drawer activity I am developing an application. One of the requirements of this app is to change
First Way
try using:
app:itemIconTint="@color/color_pink" //selected icon color
app:itemTextColor="@color/color_pink" //selected text color
app:itemBackground="@color/color_gray"
For your NavigationView
Second Way
For programetically change use:
navigationView.setItemTextColor(ColorStateList1);
navigationView.setItemIconTintList(ColorStateList2);
Define ColorStateList1
and ColorStateList2
as:
For Navigation View Item Text Color
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.BLUE,
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.BLUE,
Color.WHITE,
Color.WHITE
};
ColorStateList ColorStateList2 = new ColorStateList(states, colors);