简体   繁体   中英

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:

这个例子

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM