如何在activity中隐藏导航栏

来源:互联网 发布:电脑录音软件下载 编辑:程序博客网 时间:2024/05/16 10:59

网上翻页了很多文章 

如果没有破解权限。。

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();        }    }


13down voteaccepted

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);



13down voteaccepted

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
原创粉丝点击