是否有可能在 Android 12 中获得未裁剪的启动画面?
Is it possible to get an uncropped splash screen in Android 12?
在 Android 版本早于 Android 12 的情况下,我可以很容易地使用未裁剪的图像构建启动画面。例如在 Android 11:
然而,Android 12 引入了一个新的闪屏 API 我不知道如何在 Android 12 中重现上面的闪屏。看来是总是在 Android 12:
上裁剪成这样
这是我的 android/src/main/res/values/styles.xml
旧 Android 版本(例如 Android 11):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:windowFullscreen">false</item>
</style>
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
这是我的 android/src/main/res/values-v31/styles.xml
Android 12:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowSplashScreenAnimatedIcon">@drawable/launch_background</item>
<item name="android:windowFullscreen">false</item>
</style>
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
两个 styles.xml
之间的唯一区别是我对 Android 12 使用 android:windowSplashScreenAnimatedIcon
,对较旧的 Android 版本使用 android:windowBackground
,如新启动画面的文档 API (https://developer.android.com/guide/topics/ui/splash-screen).
两个styles.xml
都使用@drawable/launch_background
,在android/src/main/res/drawable/launch_background.xml
中定义如下:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:gravity="fill" android:src="@drawable/background"/>
</item>
<item>
<bitmap android:gravity="center" android:src="@drawable/splash"/>
</item>
</layer-list>
@drawable/background
只是一个带有单个白色像素 (1x1) 的 .png
,而 splash.png
(1280x721) 是我想在启动画面中显示的实际图像,不应该被裁剪。我在此处上传了两个文件:https://imgur.com/a/IzyYAwP
使用新的 Android 12 启动画面 API,是否有可能获得与我使用 Android 11 得到的结果相同的启动画面(没有裁剪背景图像)?如果是,那怎么可能?
不,这不可能。新启动画面的目标是统一启动画面用户体验,裁剪是设计的一部分。
在 Android 版本早于 Android 12 的情况下,我可以很容易地使用未裁剪的图像构建启动画面。例如在 Android 11:
然而,Android 12 引入了一个新的闪屏 API 我不知道如何在 Android 12 中重现上面的闪屏。看来是总是在 Android 12:
上裁剪成这样这是我的 android/src/main/res/values/styles.xml
旧 Android 版本(例如 Android 11):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:windowFullscreen">false</item>
</style>
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
这是我的 android/src/main/res/values-v31/styles.xml
Android 12:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowSplashScreenAnimatedIcon">@drawable/launch_background</item>
<item name="android:windowFullscreen">false</item>
</style>
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
两个 styles.xml
之间的唯一区别是我对 Android 12 使用 android:windowSplashScreenAnimatedIcon
,对较旧的 Android 版本使用 android:windowBackground
,如新启动画面的文档 API (https://developer.android.com/guide/topics/ui/splash-screen).
两个styles.xml
都使用@drawable/launch_background
,在android/src/main/res/drawable/launch_background.xml
中定义如下:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:gravity="fill" android:src="@drawable/background"/>
</item>
<item>
<bitmap android:gravity="center" android:src="@drawable/splash"/>
</item>
</layer-list>
@drawable/background
只是一个带有单个白色像素 (1x1) 的 .png
,而 splash.png
(1280x721) 是我想在启动画面中显示的实际图像,不应该被裁剪。我在此处上传了两个文件:https://imgur.com/a/IzyYAwP
使用新的 Android 12 启动画面 API,是否有可能获得与我使用 Android 11 得到的结果相同的启动画面(没有裁剪背景图像)?如果是,那怎么可能?
不,这不可能。新启动画面的目标是统一启动画面用户体验,裁剪是设计的一部分。