在奥利奥使用WindowManager.LayoutParams添加应用程序覆盖后,我无法点击手机上的任何部分显示,不考虑触摸事件。 这是我的代码
int LAYOUT_FLAG;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
}
layoutParams = new WindowManager.LayoutParams(
1,
1,
LAYOUT_FLAG,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
| WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
,
PixelFormat.TRANSPARENT
);
layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
答案 0 :(得分:2)
尝试添加此附加标记WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
(unknown/2)
答案 1 :(得分:0)
我在项目中使用了它,并且正在OREO上工作
if (mIconView == null) {
mIconView = new IconView(getApplicationContext());
iconViewLayoutParams = new WindowManager.LayoutParams();
iconViewLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
iconViewLayoutParams.format = PixelFormat.RGBA_8888; //Set window transparency
iconViewLayoutParams.flags = FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE//window to accept click events
iconViewLayoutParams.x = iconViewX;
iconViewLayoutParams.y = iconViewY;
iconViewLayoutParams.windowAnimations = R.style.IconViewAnimator;
iconViewLayoutParams.width = Device.dip2px(getApplicationContext(),ICON_SIZE);
iconViewLayoutParams.height = Device.dip2px(getApplicationContext(),ICON_SIZE);
iconViewLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
windowManager.addView(mIconView,iconViewLayoutParams);
}