在Android 12之前的Android版本上,我可以很容易地构建一个带有未被裁剪的图像的闪屏。例如,在Android 11上如下所示:
然而,Android 12引入了一个新的闪屏API,我不知道如何在Android 12中再现上面的闪屏。在Android 12上,它似乎总是被裁剪,结果是这样的:
这是我的安卓老版本(例如安卓11)的android/src/main/res/values/styles.xml
:
<?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>
这是我的安卓12版android/src/main/res/values-v31/styles.xml
:
<?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
之间唯一的区别是,我在Android12上使用android:windowSplashScreenAnimatedIcon
,在旧版安卓上使用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相同的闪屏(不裁剪背景图像)?如果是,这是怎么可能的?
发布于 2021-11-03 14:28:04
不,这不可能。新的闪屏的目标是统一闪屏用户体验,裁剪是设计的一部分。
https://stackoverflow.com/questions/69755263
复制相似问题