How to use setImageTintList () in Android API <21

 imgView.setImageTintList(getResources().getColorStateList(R.color.my_clr_selector)); 

He says that calling requires API level 21 ...

How can I make it work on Android devices below API 21?

I can make it work with ImageView#setColorFilter() , but I prefer to use the ColorStateList to set the hue.

+3
source share
2 answers

To achieve this, you must use ImageViewCompat#setImageTintList() . In API 21+, it will use ImageView#setImageTintList() , as you would expect ... and in earlier versions of the platform, it will delegate to AppCompatImageView , which provides an implementation with backported support.

 ColorStateList csl = AppCompatResources.getColorStateList(context, R.color.my_color_state_list); ImageViewCompat.setImageTintList(imageView, csl); 
+16
source

Now it is available in Support Library 25.4.0. See Link

ImageViewCompat.setImageTintList (imageView, colorStateList)

+4
source

All Articles