我使用TYPE_APPLICATION_OVERLAY在应用程序上覆盖一些内容。但是,如果我要查看许可,则覆盖会消失。是否有针对API 26的更好的覆盖类型或更好的解决方案?
编辑2: 覆盖代码:
int layoutType = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY : WindowManager.LayoutParams.TYPE_PHONE;
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(layoutType);
layoutParams.format = PixelFormat.RGBA_8888;
layoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
layoutParams.token = getWindow().getDecorView().getRootView().getWindowToken();
FrameLayout frameLayout = new FrameLayout(this);
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
if (windowManager != null) {
windowManager.addView(frameLayout, layoutParams);
}
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (layoutInflater != null) {
layoutInflater.inflate(R.layout.overlay, frameLayout);
}