我有一个按钮。
Button button = (Button)findViewById(R.id.button);
button.setBakgroundResource(R.drawable.icon);
如果我想检查某个按钮使用了哪个背景资源,有可能吗?如何实现。
例如:
if (button.getResourceId()==R.drawable.icon)
使用代码做一些事情...
更新:条件为false,我希望它变成true,图像不匹配
vi.findViewById(R.id.button1).setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
v.findViewById(R.id.button1).setBackgroundResource(R.drawable.boutton_off);
Drawable aImg = (Drawable)v.findViewById(R.id.button1).getBackground();
Drawable bImg = v.getResources().getDrawable(R.drawable.boutton_off);
if(aImg==bImg){
System.out.println("On");
}else
System.out.println("off");
//main.popMessage(position);
}
});