setColorFilter not working

后端 未结 10 1460
春和景丽
春和景丽 2020-12-05 12:43

I\'m trying to implement a simple colorfilter on an imageview to turn the black image into a white image. In order to achieve that I do the following:

    we         


        
10条回答
  •  佛祖请我去吃肉
    2020-12-05 13:18

    For Android 4.3 and 4.4, setColorFilter does not work. Use DrawableCompat instead.

        val drawable = DrawableCompat.wrap(ContextCompat.getDrawable(
                context,
                R.drawable.b_clouded_rain));
        DrawableCompat.setTint(drawable, foregroundColor);
        DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN)
                .setColorFilter(Color.BLACK, PorterDuff.Mode.MULTIPLY);
    
        weatherImg.setImageResource(R.drawable.b_clouded_rain);
    

提交回复
热议问题