我真的被困在试图比较两个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
}
但它给了我一个错误