【发布时间】:2014-04-02 09:36:23
【问题描述】:
我有这个 xml
<ImageView
android:id="@+id/ImgOn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/icon_on" />
有时我想通过代码删除此图像。我看过很多帖子,比如this,
但在我的情况下,imageButton.setBackgroundResource(0); 保留了出现在我的 xml 布局中的默认图像。
您将如何以编程方式将其删除?我听说透明颜色会使一些旧设备崩溃。
更新
setImageResource(0) 也保留了 xml 的原始 src,而不是我想要的 null
【问题讨论】:
-
你试过
imageView.setImageDrawable(null);吗? -
imageButton.setImageResource(0);
-
setImageResource(0) 也离开了 xml 的原始 src