在 Android ICS 上隐藏系统栏的简单方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10445157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Easy way to hide system bar on Android ICS
提问by Tran Hoang Duy Anh
I will give my ICS tablets for users to complete a survey so I would like the user to work with my app only. They should not be able to switch to the home screen, press back buttons etc., so I would like to hide the system bar completely.
我将提供我的 ICS 平板电脑供用户完成调查,因此我希望用户仅使用我的应用程序。他们应该无法切换到主屏幕,按返回按钮等,所以我想完全隐藏系统栏。
My tablet is rooted and I know some application like thiscan help me, but I don't need all the extra functions of this app.
我的平板电脑扎根,我知道像一些应用程序 这可以帮助我,但我并不需要这个应用程序的所有附加功能。
I found this tutorialthat could help me, but if I can add the code to do my own, it would be great.
我发现这个教程可以帮助我,但如果我可以添加代码来做我自己的,那就太好了。
采纳答案by ppareit
HideBar has a kiosk mode especially for this use case.
HideBar 有一个 kiosk 模式,特别适用于这个用例。
A free download is available at http://ppareit.github.com/HideBar/. You can also find it in the market at https://play.google.com/store/apps/details?id=be.ppareit.hidebar.
可在http://ppareit.github.com/HideBar/ 上免费下载。您也可以在https://play.google.com/store/apps/details?id=be.ppareit.hidebar的市场上找到它。
If you want to incorporate it in your own test/survey application you can always contact the developer (see the links for an email). The code could be explained or an Intent
to do the hiding could be provided.
如果您想将其合并到您自己的测试/调查应用程序中,您可以随时联系开发人员(请参阅电子邮件链接)。可以解释代码或者Intent
可以提供进行隐藏的操作。
回答by TheIT
After a lot of searching on the internet, I managed to get the System Bar to hide and appear in a 4.2 device using:
在互联网上进行了大量搜索后,我设法使用以下方法让系统栏隐藏并出现在 4.2 设备中:
To Hide:
隐藏:
Runtime.getRuntime().exec("service call activity 42 s16 com.android.systemui");
Or use 79 instead of 42 for API less than 14. You may also need to include the SET_DEBUG_APP permission, in which case you need to have the application signed with the system key or installed in the /system/app/ directory.
或者,对于小于 14 的 API,使用 79 而不是 42。您可能还需要包含 SET_DEBUG_APP 权限,在这种情况下,您需要使用系统密钥对应用程序进行签名或安装在 /system/app/ 目录中。
To Show:
显示:
Runtime.getRuntime().exec("am startservice --user 0 -n com.android.systemui/.SystemUIService");
Alternatively some people have used the -a (instead of -n) option, though this was causing an error on my device:
或者,有些人使用了 -a(而不是 -n)选项,尽管这会导致我的设备出现错误:
Error: Not found; no service started.
错误:未找到;没有服务启动。
For Android 4.4, there is a new feature called immersive mode which hides both the system and status bars. The system UI is toggled by the user through the use of an edge swipe from the top or bottom of the screen. For more details take a look at:
对于 Android 4.4,有一个称为沉浸模式的新功能,可以隐藏系统栏和状态栏。用户通过使用从屏幕顶部或底部的边缘滑动来切换系统 UI。有关更多详细信息,请查看:
http://developer.android.com/reference/android/view/View.html#setSystemUiVisibility(int)
http://developer.android.com/reference/android/view/View.html#setSystemUiVisibility(int)
Using new IMMERSIVE mode in android kitkat
在 android kitkat 中使用新的 IMMERSIVE 模式
For example:
例如:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE)
回答by julian
check this link: (requires root) http://android.serverbox.ch/?p=306
检查此链接:(需要root) http://android.serverbox.ch/?p=306
similar question was posted here also: Is there a way to hide the system bar in Android 3.0? It's an internal device and I'm managing navigation
这里也发布了类似的问题: Is there a way to hidden the system bar in Android 3.0? 这是一个内部设备,我正在管理导航
or try HideBar http://ppareit.github.com/HideBar/
或尝试 HideBar http://ppareit.github.com/HideBar/
Actually you can simply put the system bar in "lights out" mode, the system bar buttons and notifications gets dimmed.
实际上,您可以简单地将系统栏置于“熄灯”模式,系统栏按钮和通知会变暗。
View v = findViewById(R.id.view_id);
v.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
回答by Seraphim's
I want to add some information to the existing replies hoping it will be useful for someone.
我想在现有回复中添加一些信息,希望对某人有用。
To get a real full screen working on my low cost China tabletsI need to edit a file located in
要在我的低成本中国平板电脑上实现真正的全屏显示,我需要编辑位于
system/build.prop
replace the text
替换文字
ro.property.tabletUI=true
with
和
#ro.property.tabletUI=true
(I comment the line). After that, I can get a full screen using
(我评论该行)。之后,我可以使用全屏显示
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
for each activity in the minfest.xml
对于 minfest.xml 中的每个活动
This solution Is good only if you sell tablets with your application and needs root privilegesto edit the system/build.prop
. So it's not a solution for all, so please do not downvote this little contribute.
此解决方案仅适用于随应用程序一起销售平板电脑并且需要 root 权限来编辑system/build.prop
. 所以这不是所有人的解决方案,所以请不要低估这个小小的贡献。
EDIT:I noticed that my tablets have hardware buttons (Home, menù and back) on the frames. So Android lets me to hide the system bar. I tryed with other tablets that haven't hardware buttons without success.
编辑:我注意到我的平板电脑的框架上有硬件按钮(Home、menù 和 back)。所以Android让我隐藏系统栏。我尝试了其他没有硬件按钮的平板电脑,但没有成功。
回答by Jacob
Google intends Android to be used for consumers only. They integrated the System UI bar more tightly into Android ICS (4.0) to prevent people from rooting the device and killing the bar that way. Attempting to delete the system bar process will prevent the OS from booting fully.
谷歌打算将 Android 仅供消费者使用。他们将系统 UI 栏更紧密地集成到 Android ICS (4.0) 中,以防止人们以这种方式生根设备并杀死栏。尝试删除系统栏进程将阻止操作系统完全启动。
If you want to restrict users from accessing the home screen, then you are out of luck with Android ICS. I would suggest finding a tablet manufacture who will preload the device with Android 2.3. Either that, or use a rooted Android 3.x device.
如果您想限制用户访问主屏幕,那么您对 Android ICS 就不走运了。我建议找一家平板电脑制造商,他们会为设备预装 Android 2.3。要么,要么使用有根的 Android 3.x 设备。
If you intend to use Android for kiosk or locked down devices, then you would be better off targeting an OS that is a bit more open.
如果您打算将 Android 用于信息亭或锁定设备,那么您最好将目标定位为更开放的操作系统。
回答by Manjia
I found a solution that, in my use case, works like a charm by hiding the menu bar even on a NOT ROOTED device:
我找到了一个解决方案,在我的用例中,它通过隐藏菜单栏甚至在非根设备上也能发挥作用:
setting this flag
设置这个标志
layoutparams.flags = 0x80000000 | layoutparams.flags;
to my window's layout parameters simply does the trick!
到我的窗口的布局参数就行了!
Here's the complete snippet i used:
这是我使用的完整片段:
Window window = getWindow();
android.view.WindowManager.LayoutParams layoutparams = window.getAttributes();
layoutparams.flags = 0x80000000 | layoutparams.flags;
window.setAttributes(layoutparams);
in my Activity onCreate.
在我的活动 onCreate 中。
To find out this I reverse engeneered a non-system Apk I found that was somehow able to do that.
为了找出这一点,我反向设计了一个非系统 Apk,我发现它以某种方式能够做到这一点。
According to the official documentation:
根据官方文档:
that "0x80000000" is the FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS introduced as a system constant in Api level 21, and it basically indicates that "this Window is responsible for drawing the background for the system bars." and since i'm not manually drawing any system bar, no menu bar is shown.
其中“0x80000000”是Api level 21中作为系统常量引入的FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,基本表示“这个Window负责绘制系统栏的背景”。由于我没有手动绘制任何系统栏,因此没有显示菜单栏。
I only tested this on a pair of Moverio BT-200 running Android ICS 4.0.3 because that is the device i'm currently working on and also because right now i don't have other device running Api levels prior to 19 under my hands to test it.
我只在一对运行 Android ICS 4.0.3 的 Moverio BT-200 上进行了测试,因为这是我目前正在使用的设备,也因为现在我手上没有其他设备运行 19 之前的 Api 级别测试它。
回答by marimaf
To complement the answers already given, and in case it is useful for someone needing a similar behaviour, there is this tutorial for android devices 4.0 and higher, it tells you how to hide the navigation bar and the status bar (they will reappear when the screen is touched again):
为了补充已经给出的答案,以防万一它对需要类似行为的人有用,有适用于 android 设备 4.0 及更高版本的教程,它告诉您如何隐藏导航栏和状态栏(它们会在再次触摸屏幕):
https://developer.android.com/training/system-ui/navigation.html
https://developer.android.com/training/system-ui/navigation.html
I realize it is not what you need exactly, but might be useful for someone else looking at this problem.
我意识到这不是您完全需要的,但可能对其他人查看此问题有用。
回答by M P Mathugama
There is a workaround to disable menu bar (not hide) in all most all tablets without rooting. But this is bit tricky, but it works clean. Several well known apps in the market at the moment using this strategy to achieve this disable menu bar feature for their apps.
有一种解决方法可以在所有大多数平板电脑中禁用菜单栏(而不是隐藏)而无需生根。但这有点棘手,但它很干净。目前市场上的几个知名应用程序都使用这种策略来实现其应用程序的禁用菜单栏功能。
- Grant admin privilege (need one time user involvement to activate).
- Set password & lock the device using device admin profile api programatically.
- Then load what ever the UIs on top of the native lock screen. (Of course this will show background lock screen whenever a transition happens between activities. But if logic is organized well, then it will be smooth & less noticed by the user)
- When need to enable back, reset password to "" using resetPassword("", 0) of device policy manager object.
- 授予管理员权限(需要一次用户参与才能激活)。
- 以编程方式使用设备管理员配置文件 api 设置密码并锁定设备。
- 然后在本机锁定屏幕顶部加载任何 UI。(当然,每当活动之间发生转换时,这都会显示背景锁定屏幕。但是如果逻辑组织得很好,那么它会很流畅并且不会被用户注意到)
- 当需要启用返回时,使用设备策略管理器对象的 resetPassword("", 0) 将密码重置为 ""。