0

在我的 android 应用程序中,我正在检查按钮的图像。然后更改它。我怎样才能做到这一点?

代码-

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);
4

1 回答 1

0

试试这个:

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);
于 2013-01-28T05:55:10.133 回答