[android] how to hide system bar and navigation bar in android

原创 2016年08月30日 10:27:59

several ways I found, the sixth is a brief way to make it:

1/

secly.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

secly is my layout , setcontent,  second activity is ok, but in main activity does not work;


2/

There is a solution starting with KitKat (4.4.2), called Immersive Mode:https://developer.android.com/training/system-ui/immersive.html

Basically, you should add this code to your onResume() method:

View decorView = getWindow().getDecorView();
decorView.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_STICKY);
I've tested this

        getWindow().getDecorView().setSystemUiVisibility(
//                        View.SYSTEM_UI_FLAG_FULLSCREEN
                                 View.SYSTEM_UI_FLAG_IMMERSIVE
                                 |View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        );

hide navigation --> appear after a click

immersive --> not after click, but apeear after back to this activity.

immersive&hide navigation --> not appear after click   neither when back 



3/waiting for update

getWindow().getDecorView().//setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
        | View.SYSTEM_UI_FLAG_FULLSCREEN
        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

it works  learn from fullscreen activity.



5/ it works after reboot.

private void hideNavigationBar(){
    try {
        Process process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        os.writeBytes("pm enable com.android.systemui\n");
        os.flush();
        os.writeBytes("exit\n");
        os.flush();
        process.waitFor();
        //////////////////////////////////////
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

if need to enable, just change "pm disable com.android.systemui\n")to enable.

&reboot

remember to reboot to make it  take effort


6/ it works well 

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.

To Show:

Runtime.getRuntime().exec("am startservice --user 0 -n com.android.systemui/.SystemUIService");

and also you can type these command in command line, after type in "adb shell" and enter.


waiting for update

found an article seems helpful:

NavigationBar的增删、去掉标题栏、全屏、键盘的显示隐藏及类型
http://bbs.16rd.com/forum.php?mod=viewthread&tid=16490
(出处: 一牛网)



android navigation bar 的一些资料

  • 2016年09月18日 15:08
  • 9.34MB
  • 下载

How To Implement Search Bar in iOS 7 Using Storyboard

Editor’s note: Like some of the programming tutorials, you may find the search bar tutorial no longe...

How to play an AVI in a status bar.

  • 2006年02月23日 09:05
  • 119KB
  • 下载

Android 平板应用隐藏状态栏和底下的导航栏(navigation bar)

Android 4.4 允许应用以两种方式进入全屏模式: 横置屏幕 (Lean Back) 和沉浸模式(Immersive)。无论使用何种方式,进入全屏模式后所有的系统栏都会被隐藏。这两种方式的不同在...

android开发笔记之虚拟键(navigation bar)的一些状态的读取

最近有一个UI适配的问题,涉及到了虚拟键()

android4.1 平板隐藏System Bar

  • 2012年11月06日 11:21
  • 898KB
  • 下载

Android 修改Navigation bar为半透明?

前言          欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处:          CSDN:http://www.csdn.net  ...
  • luckkof
  • luckkof
  • 2013年05月22日 17:06
  • 4344

android APP隐藏NavigationBar,通过修改framework隐藏/显示 navigation bar

android APP隐藏NavigationBar 1. 简介     在Android4.4.2(KITKAT)之前,只能设置:                  1)View.SYST...
  • xuwuhao
  • xuwuhao
  • 2015年06月12日 09:01
  • 3990

How to Build and Run Android L 64-bit ARM in QEMU

As many others, I can't wait to put my hands on Android running on aarch64 (arm-v8) and as many othe...

Android中 4.4-5.0 系统状态栏颜色的修改。实现Translucent System Bar

在Android 4.4之前,打开app的时候我们能看到系统顶部那条黑乎乎的通系统状态栏。但是Android 4.4开始,引入了Translucent System Bar的系特性,弥补系统通知栏突兀...
  • wsdssss
  • wsdssss
  • 2016年06月01日 16:48
  • 3118
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:[android] how to hide system bar and navigation bar in android
举报原因:
原因补充:

(最多只允许输入30个字)