华为手机有底部安卓三个按钮的导航栏,可以收起来,如果不进行处理,导航栏收起来后会导致游戏不全屏显示,因为在进入游戏的时候cocos计算屏幕分辨率(不含导航栏),后续不会重复计算
解决方案是在游戏启动的时候强制隐藏底部导航栏,让游戏强制填满整个屏幕,或者游戏从后台切进来后也隐藏导航栏
@SuppressLint("NewApi") public void hideNavigationBar() { int uiFlags = 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 if( android.os.Build.VERSION.SDK_INT >= 19 ){ uiFlags |= 0x00001000; //SYSTEM_UI_FLAG_IMMERSIVE_STICKY: hide navigation bars - compatibility: building API level is lower thatn 19,use magic number directly for higher API target level } else { uiFlags |= View.SYSTEM_UI_FLAG_LOW_PROFILE; } getWindow().getDecorView().setsystemUIVisibility(uiFlags); }
需要在onCreate onResume 和onWindowFocusChanged 中调用上面方法:
protected void onCreate(Bundle savedInstanceState){ hideNavigationBar(); super.onCreate(savedInstanceState); }
@Override public void onResume() { Log.e(TAG,"onResume called"); hideNavigationBar(); super.onResume(); LCMSDK.resume(this); }
@Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if( hasFocus ) { hideNavigationBar(); } }