南锋

南奔万里空,脱死锋镝余

cocosCreator导出Android包无法显示状态栏解决方案

cocosCreator版本:3.7.2
在默认情况下,我们导出的Android工程是不会显示我们Android手机上方的状态栏的,就是时间电池电量这些信息,会被挡住。

在网上看了很多方案都不太行,如果你也有这样的困惑,那么可以参考一下我的解决方案。

解决方案:

修改CocosActivity.javaUtils.java这两个文件,注意是CocosActivity.java而不是AppActivity.java。修改如下图
CocosActivity.java
CocosActivity.java
Utils.java

主要注释掉上图中的3行代码就行了,但是这里状态栏的颜色可能不是你想要的,可以进行一个自定义的修改。

其它

我这里还使用了自定义的主题。
修改AndroidManifest.xml,找到android:theme=字段,将其改为android:theme="@style/CustomTheme";如下图:
style/CustomTheme

res/values/中添加styles.xml文件,内容如下:

1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>

添加完之后,重新编译,即可看到状态栏。

+