imageView 不会用新的可绘制对象替换以前的可绘制对象


ImageView coloring = findViewById(R.id.badge1);
coloring.setImageResource(R.drawable.coins);

当我以编程方式设置图像视图可绘制对象时,它会添加新的可绘制对象,但像这样将前一个保留在后台

我试过了

coloring.setImageResource(0);
coloring.setImageDrawable(null);

但它仍然保留了下来。

这是因为在布局中.xml您将背景设置为图像视图在布局中尝试此操作.xml到图像

   android:src="@drawable/your_drawable"

而不是

   android:background="@drawable/your_drawable"

最新更新