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:

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() .

Suleiman

Product Designer who occasionally writes code.

You may also like...

2 Responses

  1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *