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

Android端Capacitor启动页未更新:仍显示图标而非自定义启动图

Angular + Capacitor 5 Android 14 启动页异常修复方案

问题核心原因

Capacitor 5 已原生集成 Android SplashScreen API,你手动添加的自定义启动主题、主题切换逻辑会和框架自动配置冲突,导致启动页未正确加载自定义图。

分步修复步骤

1. 还原默认样式配置

删除 android/app/src/main/res/values/styles.xml 中所有自定义的 Splash 相关主题,保留基础配置:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
</resources>

2. 修正 AndroidManifest.xml

将 MainActivity 的主题改回框架默认值,移除自定义的 Splash 主题:

<activity
    android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
    android:name=".MainActivity"
    android:label="@string/title_activity_main"
    android:theme="@style/AppTheme.NoActionBar"
    android:launchMode="singleTask"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

3. 还原 MainActivity 代码

删除手动设置主题的逻辑,回到默认结构:

public class MainActivity extends BridgeActivity {
}

4. 配置 Capacitor 启动页参数

在 capacitor.config.ts 中添加 SplashScreen 专属配置,明确指定启动图资源:

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  appId: 'capacitor.test',
  appName: 'capacitor-test',
  webDir: 'dist/capacitor-test/browser',
  server: {
    androidScheme: 'https'
  },
  splashScreen: {
    launchShowDuration: 3000,
    launchAutoHide: true,
    backgroundColor: "#ffffffff",
    androidSplashResourceName: "splash",
    androidScaleType: "CENTER_CROP",
    showSpinner: false
  }
};

export default config;

注意:androidSplashResourceName 要和你生成的启动图资源名一致,@capacitor/assets generate 会自动生成全分辨率的启动图资源(覆盖 drawable-mdpi/hdpi 等目录),不要手动修改这些目录下的文件。

5. 重新生成资源并同步

npx @capacitor/assets generate
npx cap sync android

6. 清理缓存并重新构建

cd android
./gradlew clean
./gradlew assembleDebug

7. Android 14 额外注意事项

  • 完全卸载旧版本应用后再安装新包,避免系统缓存残留
  • 确保你的源图标符合 Android 自适应图标规范(@capacitor/assets generate 会自动处理,只要源文件尺寸正确即可)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 08:04:55