更改所选导航项的文本和图标的颜色

Change the color of the selected navigation item's text and icon

我正在尝试更改导航抽屉中所选项目的图标和文本的颜色。其实我想要白色的图标和文本,但它没有按预期工作。

 <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>

nav_selector.xml 文件

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

文本和图标选择器 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" />

问题解决了,我只是把drawable改成了color。在 text_selector.xml 文件中

 <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" />