Nanfeng

Notes on software development, code, and curious ideas

Showing the Status Bar in a Cocos Creator Android Build

Cocos Creator version: 3.7.2.

By default, an exported Android project hides the phone’s status bar, including the clock and battery information. After trying several approaches, this is the solution that worked for me.

Solution

Modify CocosActivity.java and Utils.java. Note that the first file is CocosActivity.java, not AppActivity.java.

CocosActivity.java changes

Additional CocosActivity change

Utils.java change

The main change is to comment out the three lines highlighted in those images. The resulting status-bar color may not match your design, so customize it if necessary.

Optional custom theme

In AndroidManifest.xml, change the android:theme attribute to:

1
android:theme="@style/CustomTheme"

Use CustomTheme

Create 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>

Rebuild the project and the status bar should be visible.

+