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

Android 12及以上如何禁用默认启动页或缩短其时长?

Android 12+ 禁用/缩短默认启动页解决方案

Android 12及以上系统引入了Splash Screen API,系统强制应用显示启动页,旧方法(如WindowIsTranslucent)不仅无效还会导致体验问题。以下是符合系统规范的解决方案:

一、实现"无感知"启动页(替代完全禁用)

系统不允许彻底移除启动页,但可以让系统启动页与你的自定义页面无缝衔接,用户几乎无法察觉:

  1. 定义启动页主题
    在res/values/styles.xml中创建继承自Theme.SplashScreen的主题,让系统启动页与你的页面视觉一致:
<style name="AppSplashTheme" parent="Theme.SplashScreen">
    <!-- 设为自定义启动页/主页面的背景色 -->
    <item name="windowSplashScreenBackground">@color/your_splash_bg</item>
    <!-- 不需要图标则设为透明 drawable -->
    <item name="windowSplashScreenAnimatedIcon">@drawable/transparent_icon</item>
    <!-- 关闭系统启动页动画,直接消失 -->
    <item name="windowSplashScreenAnimationDuration">0</item>
    <!-- 指定启动后切换到的应用主题 -->
    <item name="postSplashScreenTheme">@style/AppTheme</item>
</style>
  1. 绑定启动Activity主题
    在AndroidManifest.xml中,将启动Activity的主题设置为上述主题:
<activity
    android:name=".MainActivity"
    android:theme="@style/AppSplashTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
  1. 立即移除系统启动页
    在启动Activity的onCreate方法中调用installSplashScreen(),让系统启动页加载完成后立即消失:
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    // 安装SplashScreen并立即移除系统启动页
    installSplashScreen()
    setContentView(R.layout.activity_main)
}

二、缩短默认启动页显示时长

若仅需缩短时长,只需调整主题中的windowSplashScreenAnimationDuration值,单位为毫秒,最小可设为0:

<item name="windowSplashScreenAnimationDuration">200</item>

注意事项

  • 禁止使用WindowIsTranslucent、WindowNoTitle等旧属性隐藏启动页,Android 12+会强制显示默认启动页,且这类属性会导致页面切换闪烁、黑屏等问题。
  • 若使用独立的自定义启动页Activity,需确保其主题背景与系统SplashTheme一致,避免视觉割裂。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 03:22:42