I'm defining a CompoundDrawable on a button and reacting for clicks on it:
mFileSelector.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_LEFT = 0;
final int DRAWABLE_TOP = 1;
final int DRAWABLE_RIGHT = 2;
final int DRAWABLE_BOTTOM = 3;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (event.getRawX() >= (mFileSelector.getRight() - mFileSelector.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
mFileSelector.setSelected(false);
mFileSelector.setPressed(false);
mFileSelector.clearFocus();
return true;
}
}
return false;
}
As you can see I've tried setSelected, setPressed and clearFocus but none of them did any good. The button stays in 'pressed' state after positive onTouch (meaning I consumed the touch event)
What you need is to change the background of your button, something like this will help you.