[英]Android: Checking Background Resource Drawable
Please help how can we do a Background Resource Check? 请帮助我们如何进行后台资源检查?
Example: 例:
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){
My Question Here, checking if button1 button drawable = example2 我的问题在这里,检查button1 button drawable是否为example2
if (..........................){
//Action
}
If not, when clicked will done another action 如果不是,单击时将执行其他操作
else {
//Another Action
}
}
You can use the getBackground()
method of the View class for both buttons and compare it like this: 您可以对两个按钮使用View类的getBackground()
方法,并进行如下比较:
if (button1.getBackground().getConstantState().equals(button2.getBackground().getConstantState())) {
}
else {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.