Cordova-Android 11及以上版本是否仍可使用全屏启动图?
能不能继续使用全屏启动图?
可以实现,虽然Cordova从Android 11开始弃用<splash>标签并强制要求配置AndroidWindowSplashScreenAnimatedIcon,但通过修改原生主题配置,依然能模拟旧版全屏启动图的效果:
修改Android主题样式
打开platforms/android/app/src/main/res/values/styles.xml,将AppTheme的父主题改为Theme.SplashScreen,并添加以下配置:<style name="AppTheme" parent="Theme.SplashScreen"> <!-- 设置全屏启动图为背景 --> <item name="windowSplashScreenBackground">@drawable/your_fullscreen_splash</item> <!-- 用透明图标占位(避免显示默认图标) --> <item name="windowSplashScreenAnimatedIcon">@drawable/transparent_icon</item> <!-- 匹配应用加载时长的动画时长 --> <item name="windowSplashScreenAnimationDuration">3000</item> <!-- 隐藏状态栏和导航栏,实现真正全屏 --> <item name="android:windowFullscreen">true</item> <item name="android:windowDrawsSystemBarBackgrounds">false</item> </style>把
your_fullscreen_splash替换为你准备的全屏启动图资源,transparent_icon是一个1x1的透明PNG即可。关联主题到启动Activity
确保AndroidManifest.xml中启动Activity的android:theme指向修改后的AppTheme:<activity android:name=".MainActivity" android:theme="@style/AppTheme">
有没有类似cordova-res的适配工具?
目前没有专门替代cordova-res生成全屏启动图的Cordova专属工具,但可以用这些方案批量生成适配不同屏幕密度的资源:
Android Studio Asset Studio
打开Android Studio,右键点击res目录 → New → Image Asset,选择对应资源类型后导入你的全屏图,它会自动生成适配mdpi、hdpi、xhdpi、xxhdpi、xxxhdpi等不同密度的资源文件,直接复制到Cordova项目的对应目录即可。Node.js脚本(sharp库)
用sharp写个简单脚本批量缩放图片,示例代码:const sharp = require('sharp'); const densities = [ { name: 'mdpi', width: 480, height: 800 }, { name: 'hdpi', width: 720, height: 1280 }, { name: 'xhdpi', width: 960, height: 1600 }, { name: 'xxhdpi', width: 1440, height: 2560 }, { name: 'xxxhdpi', width: 1920, height: 3840 } ]; densities.forEach(density => { sharp('original_splash.png') .resize(density.width, density.height) .toFile(`res/drawable-${density.name}/your_fullscreen_splash.png`) .catch(err => console.error(err)); });安装sharp后运行脚本,就能生成所有适配密度的启动图。
批量图片缩放工具
用本地桌面工具(比如Batch Image Resizer)或在线批量缩放工具,输入不同密度对应的尺寸,一次性导出所有适配版本,再手动放入Cordova项目的res/drawable-*对应目录。
内容的提问来源于stack exchange,提问作者zeropsi

