Changing text color of menu item in navigation drawer
NavigationView
has a method called setItemTextColor()
. It uses a ColorStateList
.
// 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.WHITE,
Color.WHITE,
Color.WHITE
};
ColorStateList csl = 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 csl2 = new ColorStateList(states, colors);
Here is where I got that answer. And then right after assigning my NavigationView:
if (nightMode == 0) {
navigationView.setItemTextColor(csl);
navigationView.setItemIconTintList(csl2);
}
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:background="#000"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/header"
app:itemTextColor="your color"
app:menu="@menu/drawer" />
Use app:itemIconTint in your NavigationView, ej:
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:itemTextColor="@color/customColor"
app:itemIconTint="@color/customColor"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_home"
app:menu="@menu/activity_home_drawer" />
More options:
you can also change the group title by overriding "textColorSecondary"
In your styles.xml
<style name="AppTheme.NavigationView">
<item name="android:textColorSecondary">#FFFFFF</item>
</style>
In your layout
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/activity_main_menu_drawer_drawer"
android:theme="@style/AppTheme.NavigationView"
app:itemIconTint="@color/colorPrimary"
app:itemTextColor="@color/white"/>