有玩家反馈我们的游戏在 Mix 上面无法全屏显示, 上下会有黑边. 搜索了下, 网上还没有绍如何适配的相关文章, 这里介绍下我们是如何做的.

我们可以在看看小米官方对全面屏适配工作的介绍:

这些变化也影响了手机软件的设计,最值得开发者关注的,是以下两点:

  1. 更大的屏幕高宽比
  2. 虚拟导航键

好的, 我们先按照官方的方法修改下 max_aspect 的值为 2 以上

1
<meta-data android:name="android.max_aspect" android:value="2.1" />

运行下, 发现顶部的黑条不见了, 但是底部的虚拟导航键还在. 我们接着看官方的文档:

然而这几种效果都不是我们想要的, 我们想要是隐藏虚拟导航键. Google 一下, 很容易搜索到这段代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
* 隐藏虚拟按键,并且全屏
*/
protected void hideBottomUIMenu() {
//隐藏虚拟按键,并且全屏
if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if (Build.VERSION.SDK_INT >= 19) {
//for new api versions.
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
}

加上之后发现导航键真的没有了, 但是当你点击屏幕时, 它又出现了. 继续搜索发现了这篇文章, 按照文章中的提示进行修改你的 AppActivity :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    private Cocos2dxGLSurfaceView glSurfaceView;
protected void onCreate(Bundle savedInstanceState, SplashEnum splash, long duration, boolean debug) {
...
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
...
}
@Override
public Cocos2dxGLSurfaceView onCreateView() {
glSurfaceView = super.onCreateView();
this.hideSystemUI();
return glSurfaceView;
}
@Override
public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
if (hasFocus)
{
this.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.
glSurfaceView.setSystemUiVisibility(
Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_STABLE
| Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}

搞定. 看下最终的效果: