我正在实现一个自助服务终端模式应用程序,我已经成功地使应用程序在 4.3 后没有状态栏出现的情况下全屏显示,但无法在 4.3 和 4.4 中隐藏状态栏,因为当我们在顶部向下滑动时会出现状态栏屏幕。
我试着让它全屏
- 在 list 中指定全屏主题
- 设置窗口标志即setFlags
- setSystemUiVisibility
可能重复但未找到具体解决方案
Permanently hide Android Status Bar
最后我想要的是,如何在 Activity 中永久隐藏状态栏?在 android 4.3,4.4,5,6 版本中
最佳答案
我们无法阻止在 kitkat 设备中以全屏模式显示状态,所以做了一个仍然符合要求的 hack,即阻止状态栏扩展。
为此,该应用并未全屏显示。我们在状态栏上放置了一个覆盖层并消耗了所有输入事件。它阻止了状态扩展。
注意:
- customViewGroup 是自定义类,它扩展了任何 布局(框架,相对布局等)并消耗触摸事件。
- 使用触摸事件重写onInterceptTouchEvent方法 View 组并返回 true
更新
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
customViewGroup implementation
代码:
WindowManager manager = ((WindowManager) getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE));
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
// this is to enable the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = (int) (50 * getResources()
.getDisplayMetrics().scaledDensity);
localLayoutParams.format = PixelFormat.TRANSPARENT;
customViewGroup view = new customViewGroup(this);
manager.addView(view, localLayoutParams);
关于android - 防止状态栏出现android(修改),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25284233/