Repository: godot
Issue: Need a better way to make the app theme transparent on Android
Labels: enhancement,platform:android,topic:rendering,topic:porting,usability

### Godot version

3.4.dev (1cbb1f279671fdcb046a4b7d9abdb1763b316612) + PR https://github.com/godotengine/godot/pull/51935

### System information

Android

### Issue description

Following up on https://github.com/godotengine/godot/pull/51935#discussion_r709127350
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):
https://github.com/godotengine/godot/blob/e44379612d09a7b134bdadb901de409db170268c/platform/android/java/app/src/com/godot/game/GodotApp.java#L43-L46

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:
https://github.com/godotengine/godot/blob/e44379612d09a7b134bdadb901de409db170268c/platform/android/export/export.cpp#L866

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: https://github.com/godotengine/godot/pull/51935

Setting up the project with custom build:
1. Open the MRP in editor
2. Select `Project > Install Android Build Template...` and confirm
3. Select `Project > Export... > Android` and set custom template location

Test updating the theme at runtime:

1. Open `[project folder]/android/build/res/values/themes.xml`
2. 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>
```
3. Open  `[project folder]/android/build/src/com/godot/game/GodotApp.java`
4. Change the line setting the main theme to:
```
public void onCreate(Bundle savedInstanceState) {
  setTheme(R.style.GodotAppMainThemeTransparent);
  super.onCreate(savedInstanceState);
}
```
5. Export to Android
6. Observe that transparency doesn't work

Test updating the theme at export:

7. Open `[project folder]/android/build/AndroidManifest.xml`
8. Change `android:theme="@style/GodotAppSplashTheme"` to `android:theme="@style/GodotAppSplashThemeTransparent"`
9. Export to Android again
10. Observe that transparency now works

### Minimal reproduction project

Test project:
[android-transparency.zip](https://github.com/godotengine/godot/files/7172687/android-transparency.zip)