比较Drawables android

时间:2015-08-17 06:04:13

标签: java android

我真的被困在试图比较两个drawables。我在项目中添加了一张图片,并将其设置为XML格式的按钮背景。

现在我想用我的项目drawable检查点击的按钮背景。我尝试了很多东西,但没有运气。

我也试过这段代码 -

    ImageButton btn = (ImageButton) findViewById(R.id.myImageBtn);
    Drawable drawable = btn.getDrawable();
    if (drawable.getConstantState().equals(getResources().getDrawable(R.drawable.myDrawable).getConstantState())){
       //Do your work here
    }

但它给了我一个错误

0 个答案:

没有答案