Description
Godot version
System information
Android
Issue description
Following up on #51935 (comment)
CC @m4gr3d
Problem description:
When setting transparency on Android, there's one more step to do manually in order to get a fully transparent background and see the desktop behind the app.
The Android app theme needs to be changed to:
<style name="GodotAppMainTheme" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
When using custom build, it's in [project folder]/android/build/res/values/themes.xml
.
This is not very practical, since it requires to keep track of a manual change in the theme for the custom Android build, so having it set automatically on Android export based on whether per-pixel transparency is enabled would help with usability.
Things already tried:
- Setting an alternative theme at runtime
This is the piece of code that sets the main theme when the app starts (replacing the splash screen theme):
godot/platform/android/java/app/src/com/godot/game/GodotApp.java
Lines 43 to 46 in e443796
But it seems that even at this early point it's not possible to change to a theme which has transparency enabled if the default theme doesn't have transparency enabled already.
- Changing the default theme in the export process
Alternatively, we could detect transparency at export time and modify the manifest file to switch to a transparent theme by default (for both the splash screen and the main app).
It could be done in this method:
godot/platform/android/export/export.cpp
Line 866 in e443796
But that currently doesn't work with custom builds, because the process doesn't include fixing the manifest file at export in this case (the manifest is just copied from the Android template).
This would have to be fixed to use this option, because a custom build is required for Android plugins.
Steps to reproduce
Note: This PR is required for transparency to be enabled on Android: #51935
Setting up the project with custom build:
- Open the MRP in editor
- Select
Project > Install Android Build Template...
and confirm - Select
Project > Export... > Android
and set custom template location
Test updating the theme at runtime:
- Open
[project folder]/android/build/res/values/themes.xml
- Add two extra transparent themes:
<style name="GodotAppMainThemeTransparent" parent="@style/GodotAppMainTheme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
<style name="GodotAppSplashThemeTransparent" parent="@style/GodotAppSplashTheme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
- Open
[project folder]/android/build/src/com/godot/game/GodotApp.java
- Change the line setting the main theme to:
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.GodotAppMainThemeTransparent);
super.onCreate(savedInstanceState);
}
- Export to Android
- Observe that transparency doesn't work
Test updating the theme at export:
- Open
[project folder]/android/build/AndroidManifest.xml
- Change
android:theme="@style/GodotAppSplashTheme"
toandroid:theme="@style/GodotAppSplashThemeTransparent"
- Export to Android again
- Observe that transparency now works
Minimal reproduction project
Test project:
android-transparency.zip
Activity