如何在activity中隐藏导航栏

网上翻页了很多文章 

如果没有破解权限。。

void FullScreencall() {
    if(Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
        View v = this.getWindow().getDecorView();
        v.setSystemUiVisibility(View.GONE);
    } else if(Build.VERSION.SDK_INT >= 19) {
        //for new api versions.
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        decorView.setSystemUiVisibility(uiOptions);
    }
}
它的一个安全问题:http://stackoverflow.com/a/12605313/1303691
因此,在视图创建的初期,它不可能隐藏在一个平板上的一个永久的平板上的导航。这将是隐藏的,但它会弹出触摸屏幕时。所以第二触摸屏幕可以在你的布局造成onclickevent。因此,你需要拦截这个呼叫,但我还没有管理它,我会更新我的答案时,我发现了它。还是你现在的答案了?




破解权限后就可以 有2种方式,一种是改底层xml还有一种用代码控制 还有说拦截点击事件解决点击后依然弹出的。

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


13 down vote accepted

You can't hide it but you can disable it, except home. For that you can give your application as home category and let the user choose.

<category android:name="android.intent.category.HOME" />

Rest all can be disable.

add this in manifest.

<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>

inside onCreate()

this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_home);
    View v = findViewById(R.id.home_view);
    v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);



13 down vote accepted

You can't hide it but you can disable it, except home. For that you can give your application as home category and let the user choose.

<category android:name="android.intent.category.HOME" />

Rest all can be disable.

add this in manifest.

<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>

inside onCreate()

this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_home);
    View v = findViewById(R.id.home_view);
    v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值