UIModeManager
UIModeManager is an Android plugin for Godot Engine 3.5.1. The plugin can query the current state of an Android device’s UI mode, allowing you to change your app’s UI into dark or light mode version.
Getting Started
Setup
- Download the
UIMode.gdap
andUIMode.release.aar
files from the releases page - Go into your Godot project and install the Android build template (
Project > Install Android Build Template...
) - Move both
UIMode.gdap
andUIMode.release.aar
files into theandroid/plugins
directory inside your project - Enable the plugin inside the export menu (“`Project > Export…“), on the Plugins section. You may need to add an export template for Android
Compiling from source
If there is no plugin releases for the Godot version being used, you need to compile the .aar
file for the plugin yourself.
Follow the instructions on Creating Android plugins from the Godot Docs.
Detailed instructions:
- Clone the project and open the project in Android Studio
- Download the AAR Library for Android Plugins for your chosen Godot version
- Move the downloaded
.aar
file intoapp/libs
folder - Add the
.aar
file as a dependency for the project and remove the dependency on the previous.aar
file - Select the
release
build variant - Build the project (
Build > Make Project
) - The newly generated
.aar
file for the plugin will be available in the build folder (app/build/outputs/aar/UIMode.release.aar
)
Usage
The plugin can be accessed as a Singleton from the Engine
class:
var uiModeManager
if Engine.has_singleton("UIModeManager"):
uiModeManager = Engine.get_singleton("UIModeManager")
In order to check the current UI mode of an Android device, use the following code:
# To avoid any issues, check if the app is running on an Android device before executing this line of code
var UI_MODE_FLAG = uiModeManager.get_mode()
The method Manager.get_mode()
will return a String
representing the current UI mode of the Android device.
The available flags are:
DARK_MODE
: The device is currently in dark modeLIGHT_MODE
: The device is currently in light modeUNDEFINED_MODE
: No UI mode is currently setUNKNOWN_MODE_ERROR
: Error encountered
You can then use the flags in order to change the UI of the app inside Godot, such as changing the theme used for the Control
nodes.