禁用Android 12个默认启动画面
Disable Android 12 default splash screen
在 google I/O 演示中,google 团队表示我们可以禁用默认启动画面。我想做,但是找不到方法。
有人能做到吗?
稍后编辑:
我误解了演讲者在该视频中所说的内容。看来你只能编辑默认启动画面,不能禁用它。
在 Android 12,无法选择退出初始屏幕。只能对其进行自定义:图标、window 背景、退出动画。
默认情况下,启动画面从用户触摸开始显示,直到绘制应用程序的第一帧,因此要尽量减少显示启动画面的时间,您可以尝试减少应用程序的启动时间.
您还可以实现自己的退出动画,以便从初始屏幕到应用的过渡更加无缝。
如果您之前使用了专用的 SplashScreenActivity 并想保留它 activity,那么这里是官方 docs.
的解决方法
没有直接 API 来禁用默认启动画面,但如果我们将 <item name="android:windowIsTranslucent">true</item>
添加到您的样式中
<style name="Theme.RemoveSplashScreenTheme" parent="@style/BaseTheme">
<item name="android:windowIsTranslucent">true</item>
</style>
并将其应用于初始屏幕 Activity。
<activity
android:name="com.test.SplashScreenActivity"
android:launchMode="singleInstance"
android:theme="@style/Theme.RemoveSplashScreenTheme"
android:noHistory="true" />
这会将默认的初始屏幕替换为透明屏幕。如果应用已有一个启动画面,此解决方法将消除 2 个启动画面问题。
遗憾的是,您无法通过 Android 12 台设备提供的 API 直接禁用默认启动画面。
如果您的应用有自定义启动画面并且您不想迁移到这种新方法,您可以尝试以下 hack。
基本上你要做的是在 res\values-v31\themes.xml
中覆盖启动画面主题并设置透明图标。
<!-- My custom theme for splash screen activity -->
<style name="Theme.Splash" parent="Theme.Main">
<item name="android:windowBackground">@color/background</item>
<!-- Set a transparent .png as your icon -->
<item name="android:windowSplashScreenAnimatedIcon">@drawable/transparent_image</item>
</style>
这将使您摆脱应用程序启动时启动时出现的默认应用程序图标。
在您的 Splash 主题中添加“android:windowSplashScreenAnimatedIcon”
<style name="SplashTheme" parent="AppMaterialTheme">
<item name="android:windowBackground">@drawable/bg_splash</item>
<item name="android:windowSplashScreenAnimatedIcon">@android:color/transparent</item>
并将其应用到您的 Splash activity
<activity
android:name=".view.ui.splash.SplashActivity"
android:enabled="true"
android:exported="true"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme">
在 google I/O 演示中,google 团队表示我们可以禁用默认启动画面。我想做,但是找不到方法。
有人能做到吗?
稍后编辑:
我误解了演讲者在该视频中所说的内容。看来你只能编辑默认启动画面,不能禁用它。
在 Android 12,无法选择退出初始屏幕。只能对其进行自定义:图标、window 背景、退出动画。
默认情况下,启动画面从用户触摸开始显示,直到绘制应用程序的第一帧,因此要尽量减少显示启动画面的时间,您可以尝试减少应用程序的启动时间.
您还可以实现自己的退出动画,以便从初始屏幕到应用的过渡更加无缝。
如果您之前使用了专用的 SplashScreenActivity 并想保留它 activity,那么这里是官方 docs.
的解决方法没有直接 API 来禁用默认启动画面,但如果我们将 <item name="android:windowIsTranslucent">true</item>
添加到您的样式中
<style name="Theme.RemoveSplashScreenTheme" parent="@style/BaseTheme">
<item name="android:windowIsTranslucent">true</item>
</style>
并将其应用于初始屏幕 Activity。
<activity
android:name="com.test.SplashScreenActivity"
android:launchMode="singleInstance"
android:theme="@style/Theme.RemoveSplashScreenTheme"
android:noHistory="true" />
这会将默认的初始屏幕替换为透明屏幕。如果应用已有一个启动画面,此解决方法将消除 2 个启动画面问题。
遗憾的是,您无法通过 Android 12 台设备提供的 API 直接禁用默认启动画面。
如果您的应用有自定义启动画面并且您不想迁移到这种新方法,您可以尝试以下 hack。
基本上你要做的是在 res\values-v31\themes.xml
中覆盖启动画面主题并设置透明图标。
<!-- My custom theme for splash screen activity -->
<style name="Theme.Splash" parent="Theme.Main">
<item name="android:windowBackground">@color/background</item>
<!-- Set a transparent .png as your icon -->
<item name="android:windowSplashScreenAnimatedIcon">@drawable/transparent_image</item>
</style>
这将使您摆脱应用程序启动时启动时出现的默认应用程序图标。
在您的 Splash 主题中添加“android:windowSplashScreenAnimatedIcon”
<style name="SplashTheme" parent="AppMaterialTheme">
<item name="android:windowBackground">@drawable/bg_splash</item>
<item name="android:windowSplashScreenAnimatedIcon">@android:color/transparent</item>
并将其应用到您的 Splash activity
<activity
android:name=".view.ui.splash.SplashActivity"
android:enabled="true"
android:exported="true"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme">