zxd_72 2013-05-03 09:06 采纳率: 0%
浏览 2121
已采纳

如何检查view是否设置指定的背景?

我想要比较 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是否设置指定的背景?

  • 写回答

2条回答

  • JaveZh 2013-05-04 03:15
    关注

    你直接

    d == getResources().getDrawable(R.drawable.correct_ans_back)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?