永久隐藏 Android 状态栏 [英] Permanently hide Android Status Bar

查看:71
本文介绍了永久隐藏 Android 状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Android 4.4 设备上隐藏系统状态栏.这是针对自助服务终端模式的,我的应用程序将是该设备上唯一运行的应用程序.目前的目标设备是 2013 Nexus 7.

I'm trying to hide the system Status Bar on an Android 4.4 device. This is for a kiosk-mode where my app will be the only app ever run on the device. The target device for now is a 2013 Nexus 7.

设备已植根,我已经能够完全删除底部导航栏,其中包含来自 这篇文章.

The device is rooted, and I've been able to completely remove the bottom Navigation Bar with some info from this post.

对于顶部状态栏,我尝试过的一切只是暂时隐藏了状态栏.如果我的用户在屏幕顶部向下移动,状态栏会重新出现.我不想让他们看到时间、进入设置甚至看到通知.

For the top Status Bar, everything I have tried only hides the bar temporarily. If my users motion down at the top of the screen, the status bar reappears. I don't want to allow them to see the time, get to settings or even see notifications.

我找到并尝试过的帖子:

Posts I've found and already tried:

有什么建议吗?

理想情况下,我希望能够编辑 build.prop 来执行此操作,因为我已经在为导航栏执行此操作,并且可以同时执行此操作.我正在尝试不必构建自己的 android 映像.

Ideally, I'd love to be able to edit build.prop to do this, since I'm already doing that for the navigation bar, and could do this at the same time. I'm trying to not have to build my own android image.

更新:

再做一些工作后,这似乎在某种程度上取决于 android 的确切版本,或其运行的设备.

After some more work, this seems to depend somewhat on the exact build of android, or the device its running on.

某些设备(例如我一直在使用的 Nexus 系列)允许用户滑动以重新出现栏.

Some devices, such as the Nexus series I've been working with allow the user to swipe to make the bar reappear.

但是,我最近在 Verizon Eclipse 上尝试了此操作,并且该栏没有再次出现,这正是我想要的.

However, I've recently tried this on a Verizon Eclipse, and the bar does not reappear, which is what I was looking for.

我仍在寻找针对所有设备的更好的解决方案,但可能会归结为创建我自己的 android 版本.

I'm still looking for a better solution to target all devices, but it will probably come down to creating my own build of android.

推荐答案

我们无法阻止在 kitkat 设备中以全屏模式显示状态,因此做了一个仍然符合要求的 hack,即阻止状态栏扩展.

We could not prevent the status appearing in full screen mode in kitkat devices, so made a hack which still suits the requirement ie block the status bar from expanding.

为此,该应用未全屏显示.我们在状态栏上放置了一个覆盖层并消耗了所有输入事件.它阻止了状态的扩展.

For that to work, the app was not made full screen. We put a overlay over status bar and consumed all input events. It prevented the status from expanding.

注意:

  • customViewGroup 是自定义类,它扩展了任何布局(框架、相对布局等)并消耗触摸事件.
  • 消费触摸事件重写onInterceptTouchEvent方法视图组并返回true

更新

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> 

customViewGroup 实现代码:

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 状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆