Tint Icons in Android for pre Lollipop


Tint icons were first seen on Android Lollipop. The same can now be done on previous versions too with the help of Support Libraries.

Here’s on how to tint your icons:

icon icon

1. Retrieve your drawable and wrap it first. Then set the tint

Drawable drawable = getyourdrawablehere;
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable, Color.GREEN);

2. Set the Tint mode

DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);

If you want to retrieve the original drawable, don’t forget to unwrap using DrawableCompat.unwrap() .

Subscribe to stay updated
You'll be first to know about new articles and more. They're sent straight to your inbox!

No Spam, no BS. Promise. You can unsubscribe anytime.

App developer with an eye for design. Loves to create apps with good UI/ UX that doesn’t annoy people. In his spare time, he likes to draw and paint.

Suleiman

App developer with an eye for design. Loves to create apps with good UI/ UX that doesn’t annoy people. In his spare time, he likes to draw and paint.

You may also like...

  • Hey thanks for your awesome tip.

    One issue that I had applying exactly your approach, you can see in the image uploaded.

    So I this fix changing the tint mode to:

    DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);

    I Hope I can help someone with the same kind of issue.

    Thank you buddy.

    • Delighted to be of help.
      Thanks for dropping in your code snippet too. I’m sure a lot of people will benefit.

Subscribe to stay updated
You'll be first to know about new articles and more. They're sent straight to your inbox!
No Spam, no BS. Promise. You can unsubscribe anytime.
Gradle setup, ProGuard rules, Material Design palette, metrics and much more

FREE Material Design Starter Project

For more details, click on the below link.
GET IT NOW FOR ANDROID STUDIO!
Download FREE
STARTER PROJECT
Material Design Template Project for Android Studio
DOWNLOAD STARTER PROJECT
95% OFF on Machine Learning with Python Course

Use Coupon Code: CODESTARS