How to use setImageTintList() on Android API < 21

后端 未结 3 1863
走了就别回头了
走了就别回头了 2021-02-07 11:48
imgView.setImageTintList(getResources()
      .getColorStateList(R.color.my_clr_selector));

It says \'Call requires API level 21\'.

How can I m

相关标签:
3条回答
  • 2021-02-07 11:48

    You should use ImageViewCompat#setImageTintList() to achieve this. On API 21+, it will use ImageView#setImageTintList() as you would expect... and on older platform versions, it will delegate to AppCompatImageView which provides a backported implementation.

    ColorStateList csl = AppCompatResources.getColorStateList(context, R.color.my_color_state_list);
    ImageViewCompat.setImageTintList(imageView, csl);
    
    0 讨论(0)
  • 2021-02-07 11:57
    ImageViewCompat.setImageTintList(ivImage, ColorStateList.valueOf(ContextCompat.getColor(context, R.color.primaryColor)));
    
    0 讨论(0)
  • 2021-02-07 12:05

    This is now available in Support Library 25.4.0. See Link

    ImageViewCompat.setImageTintList(imageView, colorStateList)

    0 讨论(0)
提交回复
热议问题