问题
I have drawn an overlay using WindowManager. it's width and height are
WindowManager.LayoutParams.MATCH_PARENT
with transparent background.
My view must be match parent and handle circle touch listener and pass the rest touch to the below screen
I have two small circle in left and right corner
. I make them draggable on screen that's working fine. But when I click on visible Home Screen button. WindowManager don't let the visible item clickable.
int LAYOUT_FLAG = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? WindowManager.
LayoutParams.TYPE_APPLICATION_OVERLAY : WindowManager.LayoutParams.TYPE_PHONE;
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,//changed it to full
WindowManager.LayoutParams.MATCH_PARENT,
LAYOUT_FLAG,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
|WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
///| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, this flag can make it in touchable.
///WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
PixelFormat.TRANSLUCENT);
mFloatingView = LayoutInflater.from(this).inflate(R.layout.item_circle_dragging, null);
mFloatingView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return false;
}
});
//Add the view to the window
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mFloatingView,params);
item_circle_dragging.xml
<?xml version="1.0" encoding="utf-8"?>
<customviewpracticing.CircleDraggingView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</customviewpracticing.CircleDraggingView>
CircleDragginView onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if(isPointInside(event.getRawX(),event.getRawY()))
isAllowedToDrag = true;
Log.d(TAG, "ACTION_DOWN:getRawX= " + event.getRawX() + " getRawY= " + event.getRawY() + " getX= "
+ event.getX() + " getY= " + event.getY());
break;
///return true;
case MotionEvent.ACTION_MOVE:
Log.d(TAG, "ACTION_MOVE:getRawX= " + event.getRawX() + " getRawY= " + event.getRawY() + " getX= "
+ event.getX() + " getY= " + event.getY());
if(isAllowedToDrag){
center_circle_X = event.getRawX() ;
center_circle_Y = event.getRawY();
}/*this.animate().x(event.getRawX()).y(event.getRawY())
.setDuration(50).start();*/
break;
case MotionEvent.ACTION_UP:
if(isAllowedToDrag)
isAllowedToDrag = false;
break;
default:
return true;//I changed it
}
// Force a view to draw again
///postInvalidate();
invalidate();
return true;
}
Also tried returning false in onTouchEvent
of CircleDraggingView
and also to main mFloatingView (Root View ).
来源:https://stackoverflow.com/questions/51924911/windowmanager-not-allowing-to-pass-touch