How to hide the navigation bar in Android 6.0?

99封情书 提交于 2019-12-06 01:55:57

Looking back on my question, I'd like to add the solution I'm using now which hasn't failed me since, I don't remember if I saw it somewhere else or came to it myself but I'm glad it works.

public static void activiateFullscreen(Activity activity){
    View decorView = activity.getWindow().getDecorView();
    int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    if (Build.VERSION.SDK_INT >= 17) {
        uiOptions ^= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                |View.SYSTEM_UI_FLAG_LOW_PROFILE;
    }
    if (Build.VERSION.SDK_INT >= 19) {
        uiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    }
    decorView.setSystemUiVisibility(uiOptions);
}

Hope this helps someone!

I've discovered a workaround that seems to resolve this issue. I support portrait and landscape, and noticed that the black rectangle went away if I rotated into landscape or started the app in landscape. Adding the following code to my main activity's onCreate() method (after setting the immersive flags) resolved the issue:

    if (Build.VERSION.SDK_INT >= 23) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!