Change Navigation View Item Color Dynamically Android

vigonotion picture vigonotion · Jun 21, 2015 · Viewed 16k times · Source

I'd like to build a navigation drawer where each item has a different selection color (the icon tint and text color) as the google play store has:

enter image description here

I'm not sure how they've solved this, I think they use different activities with different drawers. I want to use fragments and I want to change the icon tint and text color. Any ideas how I can do this? I'm using google's design support library and a drawer layout with a navigation view in there.

Answer

DJafari picture DJafari · Jun 22, 2015

use app:itemIconTint in your NavigationView for icons and use app:itemTextColor for textColors

Sample :

drawable/navigation_text_color :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- This is used when the Navigation Item is checked -->
    <item android:color="#009688" android:state_checked="true" />
    <!-- This is the default text color -->
    <item android:color="#E91E63" />
</selector>

and layout :

<android.support.design.widget.NavigationView
       .
       .
       app:itemTextColor="@drawable/navigation_text_color"/>