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

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
(出处: 一牛网)



阅读更多
想对作者说点什么? 我来说一句

HideSystemBar android 隐藏任务栏

2013年08月17日 2.41MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭