Is there a way to hide the system/navigation bar i

2019-01-10 09:58发布

I'd like to extend the discussion regarding hiding of the system/navigation bar at the bottom of the screen on Android Ice Cream Sandwich (4.0 and up) tablet devices.

There's already a thread ( Is there a way to hide the system bar in Android 3.0? It's an internal device and I'm managing navigation ) about hiding the bar on Honeycomb devices. My clients, however, will be using the newest Ice Cream Sandwich devices and are very keen on hiding the bar at the bottom the screen. Their application is not for regular consumer use and it's very important for them to take over the whole screen to provide their experience. How possible is it to hide this bar -- or at least, override the behaviour of all the buttons -- without rooting the devices or rewriting its firmware?

12条回答
萌系小妹纸
2楼-- · 2019-01-10 10:35

EDIT: As of 4.4 (19) you can use the following to enable what is called "IMMERSIVE MODE". It was introduced for Google's Cardboard vrtoolkit, but can be used generally.

setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE)

https://developer.android.com/training/system-ui/immersive.html

From my efforts, it seems that: setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) does not work on tablets.

It does work on smartphones (tested with a Nexus 4 Mako), but it will reappear on a touch/click event. This also seems to capture focus to the bar, forcing you to click twice to regain focus to the view.

I have been trying to find a way to trap the event that actually redisplays the bar. No luck.

Being stubborn, I am going to download the android os code, fire up the eclipse debugger and go a-huntin. This is not a bug - the nav bar is crucial to app lifecycle.

I have seen apps do it (games and such) so there is a way without rooting.

查看更多
仙女界的扛把子
3楼-- · 2019-01-10 10:36

If your device is rooted this code will help you to hide system bar on ICS (I tested it on Samsung Galaxy Tab 2 and it works excellent):

ArrayList<String> list = new ArrayList<String>();
Map<String, String> env = System.getenv();
for (String envName : env.keySet()) {
    list.add(envName + "=" + env.get(envName));
}

// Array containing the environment to start the new process in
String[] envp = (String[]) list.toArray(new String[0]);

String hidingCommand = "while [ true ]\n" + "do\n" + "killall com.android.systemui\n" + "done\n";
Runtime.getRuntime().exec(new String[] { "su", "-c", command }, envp);

myContext.sendBroadcast(new Intent("com.mycompany.myapp.ACTION_BARHIDDEN"));
查看更多
smile是对你的礼貌
4楼-- · 2019-01-10 10:47

Although it's a hacky solution, I think it deserves attention because does not require rooting the device: getWindow().getDecorView().setSystemUiVisibility(8);.

查看更多
聊天终结者
5楼-- · 2019-01-10 10:47

may be is the button behavor is enought you can have a look in my answer here

you still have the bar but you can't exit app without reboot tablet

查看更多
We Are One
6楼-- · 2019-01-10 10:52

Update - there is a work around which can be used for such cases (manually setting up the app for the client). Indeed, the navigation bar can't be removed within the given framework.

However, there is a solution to hide the navigation bar if rooting the device is an option for you. Here is how:

Root device

Install and run Busybox

Install HideBar

In HideBar there is an option to run in 'Kiosk' mode, in which there is no way to re-display the navigation bar. Needless to say, you really need to be careful with this.

Risks involved:

  • bricking the device

  • getting the installation of BusyBox wrong, which could get things a bit tricky, although is very unlikely to cause loss of information.

  • getting into a stalemate where you can't quit your app. For example if 1 your GUI doesn't provide a close option, 2 your app start automatically on start-up, 3 HideBar doesn"t allow any way of re-displaying the navigation bar and 4 HideBar hids the navigation bar on startup. However this can be overcome by simply stopping/uninstalling your app from adb.

Here are other identical questions:

查看更多
Viruses.
7楼-- · 2019-01-10 10:52

To hide status bar and navigation bar in android ics use

LinearLayout layout = (LinearLayout)findViewById(R.id.layout);
layout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
查看更多
登录 后发表回答