change activity main drawer items text color programmatically android

Solutions on MaxInterview for change activity main drawer items text color programmatically android by the best coders in the world

showing results for - "change activity main drawer items text color programmatically android"
Maelyss
29 Jul 2019
1NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
2
3	//items text color
4    int[][] state = new int[][] {
5            new int[] {-android.R.attr.state_enabled}, // disabled
6            new int[] {android.R.attr.state_enabled}, // enabled
7            new int[] {-android.R.attr.state_checked}, // unchecked
8            new int[] { android.R.attr.state_pressed}  // pressed
9
10    };
11
12    int[] color = new int[] {
13            Color.WHITE,
14            Color.WHITE,
15            Color.WHITE,
16            Color.WHITE
17    };
18
19    ColorStateList colorStateList1 = new ColorStateList(state, color);
20
21
22    //icons color
23    int[][] states = new int[][] {
24            new int[] {-android.R.attr.state_enabled}, // disabled
25            new int[] {android.R.attr.state_enabled}, // enabled
26            new int[] {-android.R.attr.state_checked}, // unchecked
27            new int[] { android.R.attr.state_pressed}  // pressed
28
29    };
30
31    int[] colors = new int[] {
32            Color.WHITE,
33            Color.WHITE,
34            Color.WHITE,
35            Color.WHITE
36    };
37    ColorStateList colorStateList2 = new ColorStateList(states, colors);
38    navigationView.setItemTextColor(colorStateList1);
39    navigationView.setItemIconTintList(colorStateList2);