Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的 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);
试试这个:
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);