@@ -1037,9 +1037,14 @@ void EditorExportPlatformAndroid::_write_tmp_manifest(const Ref<EditorExportPres
1037
1037
store_string_at_path (manifest_path, manifest_text);
1038
1038
}
1039
1039
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
+
1040
1046
void EditorExportPlatformAndroid::_fix_themes_xml (const Ref<EditorExportPreset> &p_preset) {
1041
1047
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" );
1043
1048
1044
1049
if (!FileAccess::exists (themes_xml_path)) {
1045
1050
print_error (" res/values/themes.xml does not exist." );
@@ -1051,23 +1056,39 @@ void EditorExportPlatformAndroid::_fix_themes_xml(const Ref<EditorExportPreset>
1051
1056
PackedStringArray lines = file->get_as_text ().split (" \n " );
1052
1057
file->close ();
1053
1058
1059
+ // Update the themes.xml is transparency is enabled.
1060
+ bool should_be_transparent = _should_be_transparent (p_preset);
1061
+
1054
1062
// Check if the themes.xml already contains <item name="android:windowSwipeToDismiss"> element.
1055
1063
// 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
+
1057
1067
bool modified = false ;
1058
1068
for (int i = 0 ; i < lines.size (); i++) {
1059
1069
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
+ }
1065
1086
}
1066
1087
}
1067
1088
1068
1089
// If <item name="android:windowSwipeToDismiss"> is not found and `enable_swipe_to_dismiss` is false:
1069
1090
// 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) {
1071
1092
for (int i = 0 ; i < lines.size (); i++) {
1072
1093
if (lines[i].contains (" </style>" )) {
1073
1094
lines.insert (i, " <item name=\" android:windowSwipeToDismiss\" >false</item>" );
@@ -2882,7 +2903,8 @@ bool EditorExportPlatformAndroid::has_valid_project_configuration(const Ref<Edit
2882
2903
valid = false ;
2883
2904
}
2884
2905
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) {
2886
2908
String build_version_path = ExportTemplateManager::get_android_build_directory (p_preset).get_base_dir ().path_join (" .build_version" );
2887
2909
Ref<FileAccess> f = FileAccess::open (build_version_path, FileAccess::READ);
2888
2910
if (f.is_valid ()) {
@@ -2893,6 +2915,12 @@ bool EditorExportPlatformAndroid::has_valid_project_configuration(const Ref<Edit
2893
2915
err += " \n " ;
2894
2916
}
2895
2917
}
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
+ }
2896
2924
}
2897
2925
2898
2926
String target_sdk_str = p_preset->get (" gradle_build/target_sdk" );
0 commit comments