I\'m trying to add a night theme for my app and I\'ve wasted nearly three hours just trying to make the text and icons in my navigation drawer turn white along with the dark
This may help It worked for me
Go to activity_"navigation activity name".xml Inside NavigationView insert this code
app:itemTextColor="color of your choice"
<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" />
<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:itemBackground="@drawable/drawer_item_bg"
app:headerLayout="@layout/nav_header_home"
app:menu="@menu/app_home_drawer" />
To set Item Background using app:itemBackground
drawer_item_bg.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<solid android:color="@android:color/transparent" />
</shape>
</item>
<item android:top="-2dp" android:right="-2dp" android:left="-2dp">
<shape>
<padding android:bottom="0dp" android:left="15dp" android:right="0dp" android:top="0dp"/>
<solid android:color="@android:color/transparent" />
<stroke
android:width="0.5dp"
android:color="#CACACA" />
</shape>
</item>
</layer-list>
You can do simply by adding your theme to your navigation View.
<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"
android:background="@color/colorPrimary"
android:theme="@style/AppTheme.NavigationView"
app:headerLayout="@layout/nav_header_drawer"
app:menu="@menu/activity_drawer_drawer"/>
and in your style.xml file, you will add this theme
<style name="AppTheme.NavigationView" >
<item name="colorPrimary">@color/text_color_changed_onClick</item>
<item name="android:textColorPrimary">@color/Your_default_text_color</item>
</style>
to change text color of Navigation Drawer
we use
app:itemTextColor="@color/white"
to change incon color of navigation Drawer
use
app:itemIconTint="@color/black"
<com.google.android.material.navigation.NavigationView
android:id="@+id/naView"
app:itemIconTint="@color/black"
android:layout_width="match_parent"
app:menu="@menu/navmenu"
app:itemTextColor="@color/white"
app:headerLayout="@layout/nav_header"
android:layout_height="match_parent"
app:itemTextAppearance="?android:textAppearanceMedium"
android:fitsSystemWindows="true"
android:layout_gravity="start"
/>