Search code examples
androidnavigation-drawerandroid-navigationview

NavigationView with different icon states


like the gray and green one here

So is there a way in NavigationView specifically that I can make an icon that has different states changing dynamically like the picture above?

Currently Using these versions

compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'

Solution

  • Update: It looks like you can. See this answer.

    NavigationView provides a convenient way to build a navigation drawer, including the ability to creating menu items using a menu XML file. We’ve expanded the functionality possible with the ability to set custom views for items via app:actionLayout or using MenuItemCompat.setActionView().

    Old Answer:

    After a quick look into the official documentation and the source code of this View it isn't actually possible to do this.

    An alternative workaround, but this is very ugly, is to give each view a background Ressource which contains the right image. But please, don't do this!

    If you want to do this use the "old" way to implement the DrawerLayout layout. Put a Fragment in that which is under your control and you can design it like you want.