同一个ImageView setColorFilter后,再set任何图片都会自带滤镜效果。(有点像java对象的引用)
解决办法:
Drawable drawable = getResources().getDrawable(R.mipmap.ic_launcher).mutate(); drawable.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP); imageView.setImageDrawable(drawable);
//在Drawable源码中,mutate方法只是返回了他自身。
//而在drawable子类对该方法重写。比如BitmapDrawable@Override public Drawable mutate() { if (!mMutated && super.mutate() == this) { mBitmapState = new BitmapState(mBitmapState); mMutated = true; } return this; }
参考文章:https://www.jianshu.com/p/d11892bbe055
另外一个方法就是不改drawable本身的颜色,