I have 2 buttons with different parents.
I am trying to apply button effect onTouch of the button.
Here is my code:
public class ButtonHighlighterOnTouchListener implements OnTouchListener {
final Button button;
public ButtonHighlighterOnTouchListener(final Button imageButton) {
super();
this.button = imageButton;
}
public boolean onTouch(final View view, final MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
button.getBackground().setColorFilter(Color.parseColor("#B7B2B0"), PorterDuff.Mode.MULTIPLY);
button.invalidate();
break;
case MotionEvent.ACTION_CANCEL:
button.getBackground().clearColorFilter();
button.invalidate();
break;
case MotionEvent.ACTION_UP:
button.getBackground().clearColorFilter();
button.invalidate();
break;
}
return false;
}
}
It applies the effect to the button, but the problem is since I have 2 buttons, even when I click on one button, the effect is being applied to the other button as well.
Please help me to fix this.
Try : replacing button with view and return true instead of false;