Deep copy of a Drawable

前端 未结 4 776
旧时难觅i
旧时难觅i 2020-12-06 09:16

I have an ImageView. In its onClick I get its Drawable:

Drawable dr = ((ImageView) v).getDrawable();

And set it to a dialog\'s ImageView:

4条回答
  •  独厮守ぢ
    2020-12-06 10:01

    You should probably call dr.clone and then call mutate() on the object

    This will make the drawable not share any state

    Drawable newdr = dr.clone();
    newdr = newdr.mutate();
    

    Edit: Maybe just

    Drawable  newdr = dr.mutate();
    

    will work. Give both a try

提交回复
热议问题