From 60ce127b1e47c52199cb4962dcfb2d0483fcaeeb Mon Sep 17 00:00:00 2001 From: juneix <81808039+juneix@users.noreply.github.com> Date: Tue, 21 Apr 2026 19:42:00 +0800 Subject: [PATCH] v1.1 --- .github/patch_android.py | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/.github/patch_android.py b/.github/patch_android.py index ff9093f..f8fb647 100644 --- a/.github/patch_android.py +++ b/.github/patch_android.py @@ -211,7 +211,9 @@ else: # ── 7. 启动页 (Splash Screen) 规范适配 ─────────────────────────────────── res_dir = "android/app/src/main/res" os.makedirs(f"{res_dir}/values", exist_ok=True) +os.makedirs(f"{res_dir}/drawable", exist_ok=True) +# 写入颜色资源 colors_path = f"{res_dir}/values/colors.xml" colors_xml = """ @@ -221,7 +223,20 @@ colors_xml = """ """ with open(colors_path, "w", encoding="utf-8") as f: f.write(colors_xml) -print(" Created/Updated colors.xml") + +# 创建缩小的启动图辅助资源 (使用 inset 解决图标被裁切问题) +# 核心逻辑:将原本占满 100% 的图标缩小到 60% 左右,使其落入 Google 的圆形安全区 +splash_icon_xml = """ + +""" +with open(f"{res_dir}/drawable/splash_icon_padded.xml", "w", encoding="utf-8") as f: + f.write(splash_icon_xml) +print(" Created splash_icon_padded.xml") # ── 8. 修改主题 (Themes/Styles) 适配 Google SplashScreen API ───────────────── target_files = [ @@ -237,17 +252,27 @@ for rel_path in target_files: if os.path.exists(full_path): with open(full_path, "r", encoding="utf-8") as f: content = f.read() + + # A. 修复“第二步白屏”:将基础主题的窗体背景强行设为黑色 + # 针对 AppTheme 和 AppTheme.NoActionBar 注入 windowBackground,确保交接瞬间不闪白 + content = re.sub( + r'(]*>)(.*?)()', + r'\1\2 @color/black\n \3', + content, + flags=re.DOTALL + ) - # 定位启动主题节点,替换 parent 并注入规范属性 + # B. 适配官方启动页:精准匹配并提取 AppTheme.NoActionBarLaunch 标签块 style_block_pattern = r'(]*>)(.*?)()' m = re.search(style_block_pattern, content, flags=re.DOTALL) if m: start_tag = m.group(1) inner_items = m.group(2) + # 替换 parent 为官方支持的 Theme.SplashScreen start_tag = re.sub(r'parent="[^"]*"', 'parent="Theme.SplashScreen"', start_tag) - # 清理历史兼容属性,避免冲突 + # 清理历史可能存在的冲突属性 inner_items = re.sub(r'.*?', '', inner_items) inner_items = re.sub(r'.*?', '', inner_items) inner_items = re.sub(r'.*?', '', inner_items) @@ -255,9 +280,10 @@ for rel_path in target_files: splash_items = """ @color/black - @drawable/icon + @drawable/splash_icon_padded @style/AppTheme.NoActionBar """ + # 重构整个 style 块并原位替换回文档 new_block = f"{start_tag}{inner_items}{splash_items} " content = content[:m.start()] + new_block + content[m.end():]