cocos3.x 实现android沉浸式模式(全屏,隐藏导航栏即虚拟键)
Posted 游戏编程技术学习_UE4 U3d Ogre Cocos 交流
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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沉浸式模式(全屏,隐藏导航栏即虚拟键)的主要内容,如果未能解决你的问题,请参考以下文章
Android 沉浸式(透明)状态栏细研-超级细还附 Demo
Android 沉浸式(透明)状态栏细研-超级细还附 Demo