应用中修改多个getDrawable的相同资源id的问题分析

记录下遇到的问题:

程序中通过getDrawable加载统一资源,这个资源会在很多页面或者一个页面的不同地方使用,而当修改某一个地方的drawable的颜色等属性时,其他地方的该资源也同时变化了。

public void changeDrawableColor (int color) {
    Drawable bgDrawable     = context.getResources().getDrawable(R.mipmap.icon_loading_bg);
    Drawable centerDrawble   = context.getResources().getDrawable(R.mipmap.icon_loading_center);
    if (bgDrawable != null && centerDrawble != null) {
        bgDrawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
        centerDrawble.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
        mBackgroud.setImageDrawable(bgDrawable);
        mCenter.setImageDrawable(centerDrawble);
    }
}
drawable缓存分析: https://blog.csdn.net/hello__zero/article/details/43230149 

版权声明:本文为sun20209527原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。