@@ -1037,9 +1037,14 @@ void EditorExportPlatformAndroid::_write_tmp_manifest(const Ref<EditorExportPres
10371037 store_string_at_path (manifest_path, manifest_text);
10381038}
10391039
1040+ bool EditorExportPlatformAndroid::_should_be_transparent (const Ref<EditorExportPreset> &p_preset) const {
1041+ return (bool )get_project_setting (p_preset, " display/window/per_pixel_transparency/allowed" ) &&
1042+ (bool )get_project_setting (p_preset, " display/window/size/transparent" ) &&
1043+ (bool )get_project_setting (p_preset, " rendering/viewport/transparent_background" );
1044+ }
1045+
10401046void EditorExportPlatformAndroid::_fix_themes_xml (const Ref<EditorExportPreset> &p_preset) {
10411047 const String themes_xml_path = ExportTemplateManager::get_android_build_directory (p_preset).path_join (" res/values/themes.xml" );
1042- bool enable_swipe_to_dismiss = p_preset->get (" gesture/swipe_to_dismiss" );
10431048
10441049 if (!FileAccess::exists (themes_xml_path)) {
10451050 print_error (" res/values/themes.xml does not exist." );
@@ -1051,23 +1056,39 @@ void EditorExportPlatformAndroid::_fix_themes_xml(const Ref<EditorExportPreset>
10511056 PackedStringArray lines = file->get_as_text ().split (" \n " );
10521057 file->close ();
10531058
1059+ // Update the themes.xml is transparency is enabled.
1060+ bool should_be_transparent = _should_be_transparent (p_preset);
1061+
10541062 // Check if the themes.xml already contains <item name="android:windowSwipeToDismiss"> element.
10551063 // If found, update its value based on `enable_swipe_to_dismiss`.
1056- bool found = false ;
1064+ bool enable_swipe_to_dismiss = p_preset->get (" gesture/swipe_to_dismiss" );
1065+ bool found_enable_swipe_to_dismiss = false ;
1066+
10571067 bool modified = false ;
10581068 for (int i = 0 ; i < lines.size (); i++) {
10591069 String line = lines[i];
1060- if (line.contains (" <item name" ) && line.contains (" \" android:windowSwipeToDismiss\" >" )) {
1061- lines.set (i, vformat (" <item name=\" android:windowSwipeToDismiss\" >%s</item>" , bool_to_string (enable_swipe_to_dismiss)));
1062- found = true ;
1063- modified = true ;
1064- break ;
1070+ if (line.contains (" <item name" )) {
1071+ if (line.contains (" \" android:windowSwipeToDismiss\" >" )) {
1072+ lines.set (i, vformat (" <item name=\" android:windowSwipeToDismiss\" >%s</item>" , bool_to_string (enable_swipe_to_dismiss)));
1073+ found_enable_swipe_to_dismiss = true ;
1074+ modified = true ;
1075+ } else if (line.contains (" \" android:windowIsTranslucent\" >" )) {
1076+ lines.set (i, vformat (" <item name=\" android:windowIsTranslucent\" >%s</item>" , bool_to_string (should_be_transparent)));
1077+ modified = true ;
1078+ } else if (line.contains (" \" android:windowBackground\" " )) {
1079+ if (should_be_transparent) {
1080+ lines.set (i, " <item name=\" android:windowBackground\" >@android:color/transparent</item>" );
1081+ } else {
1082+ lines.set (i, " <!--<item name=\" android:windowBackground\" >@android:color/transparent</item>-->" );
1083+ }
1084+ modified = true ;
1085+ }
10651086 }
10661087 }
10671088
10681089 // If <item name="android:windowSwipeToDismiss"> is not found and `enable_swipe_to_dismiss` is false:
10691090 // Add a new <item> element before the closing </style> tag.
1070- if (!found && !enable_swipe_to_dismiss) {
1091+ if (!found_enable_swipe_to_dismiss && !enable_swipe_to_dismiss) {
10711092 for (int i = 0 ; i < lines.size (); i++) {
10721093 if (lines[i].contains (" </style>" )) {
10731094 lines.insert (i, " <item name=\" android:windowSwipeToDismiss\" >false</item>" );
@@ -2882,7 +2903,8 @@ bool EditorExportPlatformAndroid::has_valid_project_configuration(const Ref<Edit
28822903 valid = false ;
28832904 }
28842905
2885- if (p_preset->get (" gradle_build/use_gradle_build" )) {
2906+ bool gradle_build_enabled = p_preset->get (" gradle_build/use_gradle_build" );
2907+ if (gradle_build_enabled) {
28862908 String build_version_path = ExportTemplateManager::get_android_build_directory (p_preset).get_base_dir ().path_join (" .build_version" );
28872909 Ref<FileAccess> f = FileAccess::open (build_version_path, FileAccess::READ);
28882910 if (f.is_valid ()) {
@@ -2893,6 +2915,12 @@ bool EditorExportPlatformAndroid::has_valid_project_configuration(const Ref<Edit
28932915 err += " \n " ;
28942916 }
28952917 }
2918+ } else {
2919+ if (_should_be_transparent (p_preset)) {
2920+ // Warning only, so don't override `valid`.
2921+ err += vformat (TTR (" \" Use Gradle Build\" is required for transparent background on Android" ));
2922+ err += " \n " ;
2923+ }
28962924 }
28972925
28982926 String target_sdk_str = p_preset->get (" gradle_build/target_sdk" );
0 commit comments