I have an Imagebutton and I setColorFilter on ActionDOWN, but if user Slide the finger off the ImageButton, it remains with setColorFilter applied.
Question:
How to detect when finger slides off? Then I can apply setColorFilter(null);
ImageButton i1 = (ImageButton)v.findViewById(R.id.imageButton1); i1.setOnTouchListener(new OnTouchListener() {
@Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub ImageButton button = (ImageButton)v; String principal = "principal"; if (event.getAction() == MotionEvent.ACTION_DOWN) { button.setColorFilter(0x8066bbdd); return true; } else if (event.getAction() == MotionEvent.ACTION_UP) { button.setColorFilter(null); Intent i = new Intent(getActivity(), SubView.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.putExtra("query", principal); startActivity(i); return true; } return false; } });
You can use MotionEvent.ACTION_OUTSIDE
ImageButton i1 = (ImageButton)v.findViewById(R.id.imageButton1); i1.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
ImageButton button = (ImageButton)v;
String principal = "principal";
if (event.getAction() == MotionEvent.ACTION_DOWN) {
button.setColorFilter(0x8066bbdd);
return true;
} else if (event.getAction() == MotionEvent.ACTION_UP) {
button.setColorFilter(null);
Intent i = new Intent(getActivity(), SubView.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.putExtra("query", principal);
startActivity(i);
return true;
} else if(event.getAction() == MotionEvent.ACTION_OUTSIDE)
{
// Do some stuffs here
}
return false;
}
});
UPDATE 1:
If MotionEvent.ACTION_OUTSIDE
Doesn't worked you can try MotionEvent.ACTION_CANCEL
来源:https://stackoverflow.com/questions/14414873/how-to-detect-when-finger-slides-off-the-imagebutton