1

I am trying to change the color of the icon and text of the selected item in the navigation drawer. Actually I want the white icon and text when selected but it is not working as expected.

enter image description here

 <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:layout_weight="0.9"
            app:headerLayout="@layout/nav_header_main"
            app:itemIconTint="@drawable/text_selector"
            app:itemTextColor="@drawable/text_selector"
            app:itemBackground="@drawable/nav_selector"
            app:menu="@menu/activity_main_drawer"
            app:theme="@style/NavigationDrawerStyle"></android.support.design.widget.NavigationView>

The nav_selector.xml file

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorAccent" android:state_checked="true" />

The text and icon selector text_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/text_color_white" android:state_checked="true" />
<item android:color="@color/black_text_color" />

Nabin Dhakal
  • 1,949
  • 3
  • 20
  • 48
  • 1
    You can use Custom `NavigationView` for this have a look in this answer https://stackoverflow.com/a/51094894/7666442 – AskNilesh Aug 08 '18 at 07:11
  • 1
    check out this link : https://stackoverflow.com/questions/42700908/how-to-change-the-text-and-icon-color-of-selected-menu-item-on-navigation-drawer – zephyr Aug 08 '18 at 07:11

1 Answers1

0

The problem is solved, I just changed the drawable to color. in text_selector.xml file

 <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/text_color_white" android:state_checked="true" />
<item android:color="@color/black_text_color" />
Nabin Dhakal
  • 1,949
  • 3
  • 20
  • 48