You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MIUI13.0.10下Apache Cordova安卓应用启动页背景变灰求助

解决Cordova安卓启动页在MIUI深色模式下背景变灰+图标显示/动画问题

一、深色模式背景变灰修复

MIUI深色模式会自动给应用启动页套上深色滤镜,仅靠SplashScreenBackgroundColor无法覆盖系统行为,需在安卓主题配置里强制锁定背景色:

  1. 找到platforms/android/app/src/main/res/values/styles.xml,添加或修改启动页主题:
<style name="SplashTheme" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">#ffffff</item>
    <!-- 禁用系统深色模式适配 -->
    <item name="android:forceDarkAllowed">false</item>
</style>
  1. 在config.xml的安卓平台节点下新增主题指定:
<platform name="android">
    <!-- 保留原有配置 -->
    <preference name="AndroidWindowSplashScreenAnimatedIcon" value="res/screen/android/splashscreen.png" />
    <preference name="AndroidWindowSplashScreenDuration" value="-1" />
    <preference name="SplashScreenBackgroundColor" value="#ffffff" />
    <!-- 绑定自定义主题 -->
    <preference name="AndroidWindowSplashScreenTheme" value="@style/SplashTheme" />
</platform>

二、静态图标不显示排查

  • 检查图标路径:确认res/screen/android/splashscreen.png存在,建议用512x512尺寸的透明背景png。
  • 更新插件版本:旧版cordova-plugin-splashscreen可能不兼容新配置,执行以下命令更新:
cordova plugin remove cordova-plugin-splashscreen
cordova plugin add cordova-plugin-splashscreen@latest
  • 清理构建缓存:避免缓存导致资源不更新:
cordova clean android
cordova build android

三、实现图标上下浮动动画

需自定义安卓动画资源来实现效果:

  1. 在platforms/android/app/src/main/res/anim目录下创建float_animation.xml(无anim文件夹则新建):
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <translate
        android:duration="1500"
        android:fromYDelta="0%"
        android:toYDelta="10%"
        android:repeatMode="reverse"
        android:repeatCount="infinite"/>
</set>
  1. 修改SplashTheme添加动画配置:
<style name="SplashTheme" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">#ffffff</item>
    <item name="android:forceDarkAllowed">false</item>
    <!-- 绑定浮动动画 -->
    <item name="windowSplashScreenAnimationDuration">1500</item>
    <item name="windowSplashScreenIconAnimation">@anim/float_animation</item>
</style>

完成后重新构建项目即可测试效果,AndroidWindowSplashScreenDuration设为-1会让启动页保持到手动关闭,动画会持续循环。

内容的提问来源于stack exchange,提问作者hehe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 09:49:52