不僅如何將顏色清除爲我按鈕的默認顏色,而且還在我的代碼的哪一刻執行此操作?我嘗試了一切,但沒有運氣。當我點擊一個按鈕時,我設置了一些不透明的綠色。現在,當我點擊下一個按鈕時,同樣的情況發生,但第一個按鈕仍然設置爲綠色。我需要它恢復到原來的顏色。 我試着用:如何清除按鈕的顏色?
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;
}
}
}
};
類似的問題在這個職位回答。請檢查 [清除按鈕顏色] [1] [1]:http://stackoverflow.com/questions/15704898/how-to-clear-buttons-color-when-next-按鈕被點擊?rq = 1 –
我看到了,並嘗試過,但沒有奏效。 – marjanbaz