Specifically using the code below, is there a way to modify it so that the activity under this newly created view does not receive any gestures?
View v1 = new View(this); WindowManager.LayoutParams params = new WindowManager.LayoutParams( 1000, 50, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, PixelFormat.OPAQUE); params.gravity = Gravity.BOTTOM; WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE); wm.addView(v1, params);
1.1. You can react to touch events in your custom views and your activities. Android supports multiple pointers, e.g. fingers which are interacting with the screen. The base class for touch support is the MotionEvent class which is passed to Views via the onTouchEvent() method. you override the onTouchEvent() method.
Use btn. setEnabled(false) to temporarily disable it and then btn. setEnabled(true) to enable it again.
To make sure that each view correctly receives the touch events intended for it, override the onInterceptTouchEvent() method.
Touch events are delivered first to Activity. dispatchTouchEvent. It's where you may catch them first. Here they get dispatched to Window, where they traverse View hierarchy, in such order that Widgets that are drawn last (on top of other widgets) have chance to process touch in View.
Add an onTouchEvent
method to the view with top position then return true. True will tell the event bubbling that the event was consumed therefore prevent event from bubbling to other views.
protected boolean onTouchEvent (MotionEvent me) { return true; }
For v1
you would do an import:
import android.view.View.OnTouchListener;
Then set the onTouchListener:
v1.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } });
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