Skip to content

Fix transparency background issue on Android #106709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

m4gr3d
Copy link
Contributor

@m4gr3d m4gr3d commented May 22, 2025

Updates the logic to detect when transparency is required on Android using display/window/per_pixel_transparency/allowed, display/window/size/transparent, and rendering/viewport/transparent_background, which updates the render view configuration and the app's theme.

The requirement to update the app's theme means the feature is only available to gradle build exports.

Fixes #106703

Before

Screen_Recording_20250522_001406_GLTF.Viewer.mp4

After

Screen_Recording_20250522_001458_GLTF.Viewer.mp4

@m4gr3d m4gr3d added this to the 4.5 milestone May 22, 2025
@m4gr3d m4gr3d requested a review from a team as a code owner May 22, 2025 07:15
bool EditorExportPlatformAndroid::_should_be_transparent(const Ref<EditorExportPreset> &p_preset) const {
return (bool)get_project_setting(p_preset, "display/window/per_pixel_transparency/allowed") &&
(bool)get_project_setting(p_preset, "display/window/size/transparent") &&
(bool)get_project_setting(p_preset, "rendering/viewport/transparent_background");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rendering/viewport/transparent_background check is probably excessive, on desktop platforms setting display/window/size/transparent (or transparent flag for the Window) will automatically set viewport background to transparent regardless of this setting.

Comment on lines 1075 to 1121
} else if (line.contains("\"android:windowIsTranslucent\">")) {
lines.set(i, vformat(" <item name=\"android:windowIsTranslucent\">%s</item>", bool_to_string(should_be_transparent)));
modified = true;
} else if (line.contains("\"android:windowBackground\"")) {
if (should_be_transparent) {
lines.set(i, " <item name=\"android:windowBackground\">@android:color/transparent</item>");
} else {
lines.set(i, " <!--<item name=\"android:windowBackground\">@android:color/transparent</item>-->");
}
modified = true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m4gr3d Since we're now relying on multiple theme attributes, the current setup is becoming error-prone.

For example, if a user manually edits themes.xml and removes the android:windowIsTranslucent attribute, the check if (line.contains("\"android:windowIsTranslucent\">")) would fail, making this feature silently stop working.

While we could add individual found_* booleans for each attribute, that quickly gets messy.

I opened PR #106724, which re-generates the GodotAppMainTheme during export. This prevents manual changes from causing issues and adds a new export option for injecting custom theme attributes in a cleaner way.

@m4gr3d
Copy link
Contributor Author

m4gr3d commented May 23, 2025

Switching to draft until #106724 is merged.

@m4gr3d m4gr3d force-pushed the fix_transparency_flags branch from 4b60b04 to 335cc7e Compare May 28, 2025 14:17
@m4gr3d m4gr3d force-pushed the fix_transparency_flags branch from 335cc7e to 7a15ea7 Compare May 28, 2025 14:25
@m4gr3d m4gr3d marked this pull request as ready for review May 28, 2025 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android GodotFragment can't have a transparent background
3 participants