如何修改Capacitor混合应用的Android启动页(ic_launcher)背景色
Capacitor Android 启动页背景色修改方案
方法一:通过Capacitor配置文件修改(推荐,无需原生操作)
- 打开项目根目录的
capacitor.config.ts(若为JSON格式则打开capacitor.config.json) - 在
android配置节点下添加splashScreen配置,指定自定义背景色:
import { CapacitorConfig } from '@capacitor/cli'; const config: CapacitorConfig = { appId: 'com.your.app.id', appName: 'YourAppName', webDir: 'dist', android: { splashScreen: { backgroundColor: "#FF5722", // 替换为你的十六进制颜色值 // 图标无需修改,保持现有ic_launcher即可 } } }; export default config;
- 执行命令同步配置到Android项目:
npx cap sync android
方法二:直接修改Android原生文件(配置不生效时使用)
如果上述方法无效,直接修改Android端的主题或启动页背景资源:
- 打开Android项目的
app/src/main/res/values/styles.xml - 找到对应启动页的主题(通常为
SplashTheme),修改android:windowBackground属性:
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowBackground">#FF5722</item> <!-- 替换为你的自定义颜色 --> </style>
- 若启动页背景是通过layer-list drawable定义(比如
res/drawable/splash_background.xml),打开该文件修改背景色:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="#FF5722" /> <!-- 此处修改背景色 --> <item> <bitmap android:gravity="center" android:src="@mipmap/ic_launcher" /> <!-- 保留现有图标,无需改动 --> </item> </layer-list>
- 重新构建Android项目即可生效
内容的提问来源于stack exchange,提问作者Joe Schmo
相关产品推荐
相关产品推荐

