在
oreo
中,当我使用 TYPE_APPLICATION_OVERLAY 进行叠加时,仅可点击视图下方的开关。但是所有其他视图,例如按钮都无法点击。
int LAYOUT_FLAG = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? WindowManager.
LayoutParams.TYPE_APPLICATION_OVERLAY : WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
buttonParams = new WindowManager.LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
///WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
LAYOUT_FLAG,
//WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
///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_NOT_TOUCH_MODAL
//| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON,
PixelFormat.TRANSLUCENT);
buttonParams.gravity = Gravity.LEFT | Gravity.TOP;
buttonParams.x = x - button.getWidth() / 2; // FIXME: 12/8/2018 set all button to left top and bottom on start ..
buttonParams.y = y - button.getHeight() / 2;
wm.addView(button, buttonParams);
我尝试了很多标志。此问题仅发生在OREO设备中。
第二次尝试
new WindowManager.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, TYPE_SYSTEM_ERROR, FLAG_NOT_FOCUSABLE
| FLAG_NOT_TOUCH_MODAL
| FLAG_LAYOUT_NO_LIMITS
| FLAG_LAYOUT_INSET_DECOR
| FLAG_LAYOUT_IN_SCREEN, TRANSLUCENT);