Skip to content

Need a better way to make the app theme transparent on Android #52725

Open
@pouleyKetchoupp

Description

Godot version

3.4.dev (1cbb1f2) + PR #51935

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):

public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.GodotAppMainTheme);
super.onCreate(savedInstanceState);
}

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:

void _fix_manifest(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_manifest, bool p_give_internet) {

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:

  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>
  1. Open [project folder]/android/build/src/com/godot/game/GodotApp.java
  2. Change the line setting the main theme to:
public void onCreate(Bundle savedInstanceState) {
  setTheme(R.style.GodotAppMainThemeTransparent);
  super.onCreate(savedInstanceState);
}
  1. Export to Android
  2. Observe that transparency doesn't work

Test updating the theme at export:

  1. Open [project folder]/android/build/AndroidManifest.xml
  2. Change android:theme="@style/GodotAppSplashTheme" to android:theme="@style/GodotAppSplashThemeTransparent"
  3. Export to Android again
  4. Observe that transparency now works

Minimal reproduction project

Test project:
android-transparency.zip

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions