请帮助我们如何进行背景资源检查?
例子:
Button button1;
protected void onCreate(Bundle savedInstanceState) {
..........................................
button1 = (Button) findViewById(R.id.example1);
}
public void onclick1 (View v){
button1.setBackgroundResource(R.drawable.example2);
}
public void onclick2 (View v){
我的问题在这里,检查 button1 button drawable = example2
if (..........................){
//Action
}
如果没有,点击时会做另一个 Action
else {
//Another Action
}
}
最佳答案
您可以使用 getBackground()
两个按钮的 View 类的方法并像这样比较它:
if (button1.getBackground().getConstantState().equals(button2.getBackground().getConstantState())) {
}
else {
}
关于Android:检查背景资源可绘制对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16375289/