安卓隐藏导航栏后出现黑边,求大神指导

问题描述:
1.未隐藏导航栏进入游戏时,如下图

2.游戏中隐藏导航栏后,如下图

3.退出游戏,先隐藏导航栏,再进游戏,如下图

求指导:
第二步隐藏的时候,如何变成第三张图那样,全屏显示无黑边

环境:
华为荣耀6 Android4.4.2
cocos2d-x3.2 cpp
android:minSdkVersion=“9” 这个不准备改

遇到同样的问题,求解

刚玩了一下刀搭传奇,也有这个问题,楼主如果解决了,还望共享!

算是自己解决了吧,网上找的段代码,让4.0以上的机器强制隐藏导航栏后进入游戏

@SuppressLint("NewApi")
protected void onCreate(final Bundle savedInstanceState) {
    if (Build.VERSION.SDK_INT >= 16)  {
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
    }
    ...
}

不过还是有点小问题,当手动拉出导航栏时,会挡住游戏,不像别的某些程序,会根据导航栏调整窗体大小

1赞

恩,确实有用,感谢楼主分享

但是,点击按钮的时候,位置会偏移

from 3.16

    protected void hideVirtualButton() {
        // if (showVirtualButton) {
        //     return;
        // }

        if (Build.VERSION.SDK_INT >= 19) {
            // use reflection to remove dependence of API level

            Class viewClass = View.class;

            try {
                final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = Cocos2dxReflectionHelper.<Integer>getConstantValue(viewClass, "SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION");
                final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = Cocos2dxReflectionHelper.<Integer>getConstantValue(viewClass, "SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN");
                final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = Cocos2dxReflectionHelper.<Integer>getConstantValue(viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION");
                final int SYSTEM_UI_FLAG_FULLSCREEN = Cocos2dxReflectionHelper.<Integer>getConstantValue(viewClass, "SYSTEM_UI_FLAG_FULLSCREEN");
                final int SYSTEM_UI_FLAG_IMMERSIVE_STICKY = Cocos2dxReflectionHelper.<Integer>getConstantValue(viewClass, "SYSTEM_UI_FLAG_IMMERSIVE_STICKY");
                final int SYSTEM_UI_FLAG_LAYOUT_STABLE = Cocos2dxReflectionHelper.<Integer>getConstantValue(viewClass, "SYSTEM_UI_FLAG_LAYOUT_STABLE");

                // getWindow().getDecorView().setSystemUiVisibility();
                final Object[] parameters = new Object[]{SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                        | SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                        | SYSTEM_UI_FLAG_IMMERSIVE_STICKY};
                Cocos2dxReflectionHelper.<Void>invokeInstanceMethod(getWindow().getDecorView(),
                        "setSystemUiVisibility",
                        new Class[]{Integer.TYPE},
                        parameters);
            } catch (NullPointerException e) {
                Log.e(TAG, "hideVirtualButton", e);
            }
        }
    }