editbox安卓平台下隐藏导航栏(转载)

出自:http://www.cnblogs.com/gamesky/p/8485272.html

只有在Android 4.4及以上系统才支持沉浸式模式,修改 AppActivity代码如下:

复制代码
    @Override
    public Cocos2dxGLSurfaceView onCreateView() {

        Cocos2dxGLSurfaceView glSurfaceView = super.onCreateView();

        hideSystemUI();

        return glSurfaceView;
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus && Build.VERSION.SDK_INT >= 19) {

            hideSystemUI();
        }
    }
    private void hideSystemUI()
    {
        // Set the IMMERSIVE flag.
        // Set the content to appear under the system bars so that the content
        // doesn't resize when the system bars hide and show.
        if (Build.VERSION.SDK_INT >= 19)
        {
            Cocos2dxGLSurfaceView decorView =Cocos2dxGLSurfaceView.getInstance();
            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 // hide nav bar
                            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }

    }
复制代码

 

另外如果打开了全屏的输入法时,需要再次做隐藏处理,在Cocos2dxEditBoxHelper.java  createEditBox中失去焦点的回调中添加:

复制代码
                
editBox.setOnFocusChangeListener(new View.OnFocusChangeListener() {

@Override
public void onFocusChange(View v, boolean hasFocus) {
...

//
全屏设置 if (Build.VERSION.SDK_INT >= 19) { Cocos2dxActivity cocosAct=(Cocos2dxActivity)Cocos2dxActivity.getContext(); Cocos2dxGLSurfaceView view=cocosAct.getGLSurfaceView(); view.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 // hide nav bar | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); }
复制代码

 在Cocos2dxGLSurfaceView.java    protected void initView() 中关闭键盘的回调中添加:

复制代码
case HANDLER_CLOSE_IME_KEYBOARD:
                        ...//全屏设置
                            if (Build.VERSION.SDK_INT >= 19)
                            {
                                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 // hide nav bar
                                                | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                                                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
                            }
                        }
                        break;
复制代码

猜你喜欢

转载自blog.csdn.net/chenbingzhao/article/details/80048714