如何在系统 ui 模式更改后更改屏幕覆盖(全屏,隐藏导航)?
How to change Screen overlay after system ui mode changed(Fullscreen, hide navigation)?
我创建叠加层:
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
/*The parent view (actually the root view) the will be added in front of all the windows on the screen*/
mOverlayView = (RelativeLayout) inflater.inflate(R.layout.overlay_control, null);
mWindowManager.getDefaultDisplay().getSize(size);
mWindowSize = new Size(size.x, size.y);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS |
WindowManager.LayoutParams.FLAG_FULLSCREEN,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.LEFT;
mWindowManager.addView(mOverlayView, params);
如果系统 UI 可见性发生变化,我需要移动叠加层。有可能检测到它(documentation)以供查看,但它不适用于叠加。所以我只需要回调来检测设备模式是否改变。
我找到了方法:
在 Android 中有 OnSystemUiVisibilityChangeListener
,但如果没有具有 match_parent
宽度或高度值的视图,它就不起作用。
所以我创建了这样的叠加层并将其设为 1 px 高度和 match_parent
宽度并向其添加 OnSystemUiVisibilityChangeListener
。
我创建叠加层:
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
/*The parent view (actually the root view) the will be added in front of all the windows on the screen*/
mOverlayView = (RelativeLayout) inflater.inflate(R.layout.overlay_control, null);
mWindowManager.getDefaultDisplay().getSize(size);
mWindowSize = new Size(size.x, size.y);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS |
WindowManager.LayoutParams.FLAG_FULLSCREEN,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.LEFT;
mWindowManager.addView(mOverlayView, params);
如果系统 UI 可见性发生变化,我需要移动叠加层。有可能检测到它(documentation)以供查看,但它不适用于叠加。所以我只需要回调来检测设备模式是否改变。
我找到了方法:
在 Android 中有 OnSystemUiVisibilityChangeListener
,但如果没有具有 match_parent
宽度或高度值的视图,它就不起作用。
所以我创建了这样的叠加层并将其设为 1 px 高度和 match_parent
宽度并向其添加 OnSystemUiVisibilityChangeListener
。