【发布时间】:2012-12-13 18:27:43
【问题描述】:
在xml中:
<ImageButton
android:id="@+id/b_checkEv"
android:src="@drawable/img_huella"
... />
活动中:
ImageButton ib = (ImageButton) findViewById(R.id.b_checkEv);
Drawable dr = ib.getDrawble();
我使用 ib.setDrawable() 在代码中动态更改 ImageButton 的图像。 任何人都知道我如何从 Drawable 中获取资源 ID,以便知道每个时刻在 ImageButton 中设置了哪个图像?
谢谢!
【问题讨论】:
-
您可以只维护一个包含此值的 int。前任。 int currentImage = R.drawable.image; ib.setDrawable(currentImage);
标签: android resources drawable imagebutton