不仅如何将颜色清除为按钮的默认颜色,而且在我的代码中什么时候执行?我已经尝试了一切,但没有运气。当我单击一个按钮时,我设置了一些不透明度的绿色。现在,当我单击下一个按钮时,会发生同样的情况,但第一个按钮仍设置为绿色。我需要它恢复到原来的颜色。我试过:
button.getBackground().setColorFilter(null);
这是我的代码:
final OnClickListener clickListener = new OnClickListener() {
private Button buttonClicked;
public void onClick(View v) {
Button button = (Button) v;
button.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0x003333));
if (buttonClicked == null) {
// first button is clicked
buttonClicked = button;
// only do stuff if buttons are in different layouts
} else{
if (!button.getParent ().equals(buttonClicked.getParent())) {
// second button is clicked
if(buttonClicked.getTag().equals(button.getTag()) ){
// second button is clicked and same tag but different button
Toast.makeText(Spojnice.this, "Correct", Toast.LENGTH_SHORT).show();
button.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0x66FF33));
buttonClicked.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0x66FF33));
buttonClicked.setEnabled(false);
button.setEnabled(false);
buttonClicked = null;
} else {
//reset LightingColorFilter first
Toast.makeText(Spojnice.this, "Wrong", Toast.LENGTH_SHORT).show();
buttonClicked = null;
}
}else{
buttonClicked = button;
}
}
}
};