我想要比較 view background 和 drawable,但是沒成功
View v1 = options.findViewById(i);
v1.findViewById(R.drawable.back);
Drawable d = v1.getBackground();
if(d.getConstantState() == getResources().getDrawable(R.drawable.correct_ans_back)){
v1.setBackgroundResource(R.drawable.a);
}else{
view.setBackgroundResource(R.drawable.b);
}
下面是錯誤提示:
incompatible operand types Drawable.Constant State and Drawable
如何檢查view是否設置指定的背景?
你直接
d == getResources().getDrawable(R.drawable.correct_ans_back)