2013-05-04 109 views
2

请帮助我们如何做背景资源检查?Android:检查背景资源可绘制

例子:

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的按钮可绘制=例题

 if (..........................){ 
       //Action 
     } 

如果不是,点击会完成其他操作时

 else { 
       //Another Action 
     } 
    } 

回答

4

您可以使用两个按钮的View类的getBackground()方法,并像这样比较它:

if (button1.getBackground().getConstantState().equals(button2.getBackground().getConstantState())) { 
    } 
else { 
    } 
+0

谢谢,它的工作原理 – user2341387 2013-05-04 14:36:11