Reputation: 7109
The NavigationView does a color tinting on the icons if they colored. My icon is green and in the NavigationView it is grey. How does this work?
I want to do this myself in a other view, but I didn't find how NavigationView do this.
Upvotes: 1
Views: 1113
Reputation: 9683
This blog post explains AppCompat tinting of drawables. Is this what you're looking for?
The Drawable tinting methods added in Lollipop are super useful for letting you dynamically tint assets. AppCompat had its own baked in implementation in the v21 support library and we’ve now extracted that into DrawableCompat in support-v4 for everyone to use. It’s important to know how it works though.
Drawable drawable = ...; // Wrap the drawable so that future tinting calls work // on pre-v21 devices. Always use the returned drawable. drawable = DrawableCompat.wrap(drawable); // We can now set a tint DrawableCompat.setTint(drawable, Color.RED); // ...or a tint list DrawableCompat.setTintList(drawable, myColorStateList); // ...and a different tint mode DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_OVER);
Or if you just want to tint an ImageView, you can do this:
ImageView image = (ImageView) findViewById(R.id.image);
image.setColorFilter(...);
Upvotes: 3