cocos3.x实现android沉浸式模式(全屏,隐藏导航栏即虚拟键)

临文乍了了,彻卷兀若无。这篇文章主要讲述cocos3.x实现android沉浸式模式(全屏,隐藏导航栏即虚拟键)相关的知识,希望能为你提供帮助。
只有在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;

 
【cocos3.x实现android沉浸式模式(全屏,隐藏导航栏即虚拟键)】效果如下:
cocos3.x实现android沉浸式模式(全屏,隐藏导航栏即虚拟键)

文章图片


    推荐阅读