Stacksr
Stacksr

Reputation: 23

Changing the icon colour of individual Navigation Drawer icons

This question has been asked before in comments on other threads but no-one has ever got a straight answer as far as I can see.

What I'm looking to do is style every individual icon in a nav draw to be tinted with different colours. Here's an example:

The example

Using app:itemIconTint will style all icons. Is there a possible way to do this?

Upvotes: 2

Views: 1493

Answers (2)

Anthone
Anthone

Reputation: 2290

onCreate methode of Activity

navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setItemIconTintList(null);
//For each icon
navigationView.getMenu()
                .findItem(R.id.home)
                .getIcon()
                .setColorFilter(getResources().getColor(R.color.yellow), PorterDuff.Mode.SRC_IN);

Upvotes: 3

Zibi
Zibi

Reputation: 554

In onCreate() method put this:

NavigationView nw = (NavigationView) findViewById(R.id.nav_view); nw.setItemIconTintList(null);

and then all your icons will be shown in their original color. Basically all you need to create are colored icons.

Upvotes: 5

Related Questions