I have an activity in which I want to avoid the user touch buttons during a time.
I make this:
WindowManager.LayoutParams params = getWindow().getAttributes();
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setAttributes(params);
It works great, but when I come back to receive touch events with:
WindowManager.LayoutParams params = getWindow().getAttributes();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setAttributes(params);
I receive all the events relatives to the user touchs during the period not touchable.
Any idea how to discard this events?
I face the same problem but I come up with a workaround without messing up with window flag. Try this:
@Override
public boolean dispatchTouchEvent (MotionEvent ev){
if(activityTouchable == false)return true;
else return super.dispatchTouchEvent(ev);
}
@Override
public boolean dispatchKeyEvent (KeyEvent event){
if(activityTouchable == false)return true;
else return super.dispatchKeyEvent(event);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With