在早于 Android 12 的 Android 版本上,我可以轻松构建带有未裁剪图像的启动屏幕。例如 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>
Run Code Online (Sandbox Code Playgroud)
这是我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>
Run Code Online (Sandbox Code Playgroud)
两者之间的唯一区别styles.xml
是我用于android:windowSplashScreenAnimatedIcon
Android 12 和android:windowBackground
旧版 Android 版本,如新启动屏幕 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>
Run Code Online (Sandbox Code Playgroud)
@drawable/background
只是一个.png
带有单个白色像素(1x1)的图像,splash.png
(1280x721)是我想在启动屏幕中显示的实际图像,不应被裁剪。我在这里上传了两个文件: https: //i.stack.imgur.com/x3QU9.jpg
使用新的 Android 12 启动屏幕 API,是否有可能获得与 Android 11 获得的结果相同的启动屏幕(不裁剪背景图像)?如果是,那怎么可能?
归档时间: |
|
查看次数: |
3166 次 |
最近记录: |