关闭

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

239人阅读 评论(0) 收藏 举报

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



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1297次
    • 积分:140
    • 等级:
    • 排名:千里之外
    • 原创:14篇
    • 转载:2篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档