A little stupid question ... I have a Drawer specified via xml using DrawerLayout. I fill the draver myself through menu-res. How to change text color of selected item? It is the color of the text, not the background.

Now so

I tried to change the android:textColorPrimary parameter in styles.xml , but it colors all menu items. The highlighted item is still black.

How to change color correctly?

On this site I found only an example of changing the background color in the drover from ListView, it does not suit me. It seems to be such a simple task, but I can not solve it.

  • Do you have NavigationView or ListView there? - Yuriy SPb ♦
  • NavigationView. Yuzayu standard template from Android Studio. - De-Bill

1 answer 1

  1. Create a file navigation_view_selector.xml in res/color
  2. Set there the necessary colors for the necessary states

     <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="#724646" android:state_checked="true"/> <item android:color="#724646" android:state_pressed="true"/> <item android:color="#724646"/> </selector> 
  3. In the markup, set this selector to NavigationView

     app:itemIconTint="?navigationViewItemIconColor" app:itemTextColor="?navigationViewItemTextColor" 
  4. Also something that can be set through styles

      <style name="navigationStyle" parent="SCP.Theme.Light"> <item name="colorControlHighlight">#ff0000</item> <item name="android:windowBackground">#00ff00</item> </style> 

    which can also be set in

     style="@style/navigationStyle"