我的 onClickListener 中有此代码(我还有其他内容,但与此问题无关:
final OnClickListener clickListener = new OnClickListener() {
public void onClick(View v) {
Button button = (Button) v;
button.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0x003333));
}
}
当我按下它时,我将按钮颜色设置为绿色(有一些不透明度)。如何清除该颜色,将其重置为我的默认按钮颜色(不是 Android 默认值,我的默认设置颜色),并且只有当前按下的按钮为绿色?
编辑:
这是我的整个 onClickListener 代码:
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 () != buttonClicked.getParent()) {
// second button is clicked
if (buttonClicked.getTag().equals(button.getTag())) {
Toast.makeText(Spojnice.this, "Tacno", Toast.LENGTH_SHORT).show();
button.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0x66FF33));
buttonClicked.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0x66FF33));
buttonClicked.setEnabled(false);
button.setEnabled(false);
} else {
Toast.makeText(Spojnice.this, "Netacno", Toast.LENGTH_SHORT).show();
//buttonClicked.setEnabled(false);
//buttonClicked.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFFCC99));
//button.getBackground().clearColorFilter();
}
buttonClicked = null;
}
}
};