How To Clear Button's Color When Next Button Is Clicked?
How to change button's color to default after next button is clicked? I have this code that sets color to the button in onclicklistener: Button button = (Button) v; button.getBackg
Solution 1:
Either, store the reference to the previous button in the scope of your activity and use it in the onclick to reset it. Or set background of all buttons, except the one which is clicked.
Button previousButton = null;
@Override
public void onClick(View v) {
//reset old button
if (previousButton != null) {
previousButton.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0x000000));
}
//prettify new button
Button button = (Button) v;
button.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0x003333));
previousButton = button;
}
Post a Comment for "How To Clear Button's Color When Next Button Is Clicked?"