在安卓應用中,檢測button的圖片,然後修改。怎麼實現?
我的代碼如下:
Drawable a;
a=b1.getBackground();
int i=R.drawable.happy;
// b1 is button
if(a==R.drawable.happy)
b1.setBackgroundResource(R.drawable.whoa);
else
b1.setBackgroundResource(R.drawable.happy);
Drawable a = b1.getDrawable();
Drawable image = getResources().getDrawable(R.drawable.happy);
// b1 is button
if(image.equals(a))
b1.setBackgroundResource(R.drawable.whoa);
else
b1.setBackgroundResource(R.drawable.happy);
試試這個