gpt4 book ai didi

api 21 之前的 Android 12 启动画面

转载 作者:行者123 更新时间:2023-12-04 23:40:41 24 4
gpt4 key购买 nike

我正在尝试将我的应用程序升级到目标 android 31,它引入了启动屏幕 API,所以我遵循了提到的迁移过程 here ,但迁移后应用程序无法运行,因为闪屏 API 仅支持 android 版本 21 及更高版本,那么支持旧版本 21 的过程是什么?
enter image description here

最佳答案

Androidx SplashScreen类工作如下:
在 API 31+ (Android 12+) 上,此类调用平台方法。
在 API 31 之前,平台行为被复制,但 除外。动画矢量可绘制 启动屏幕上的支持。
问题是Animated Vector Drawable类是随 Android 21 引入的,因此当前的 Androidx SplashScreen 类向后兼容 Android +21,所以我想出了一些解决方案。
我创建了两种不同的闪屏 Activity ,一种是处理旧版本,另一种是使用 Androidx SplashScreen API。我根据当前的android版本制作了系统午餐启动画面,所以我做了以下
1-为了允许应用程序编译和构建,我必须将此行添加到我的 list 文件中

<uses-sdk tools:overrideLibrary="androidx.core.splashscreen"/>
2- 按照 migration 创建使用 Androidx SplashScreen API 的新启动屏幕 Activity 文档中的步骤。
3- 在 values 文件夹下创建 bools.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="new_splash_enabled">false</bool>
<bool name="old_splash_enabled">false</bool>
</resources>
4- 覆盖 values-vX 中的 bools.xml(X 是 minSdkVersion)在我的情况下是 16,所以我在同一级别的 values 文件夹中创建了 values-v16 文件夹,并在其下创建 bools.xml,如下所示
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="new_splash_enabled">false</bool>
<bool name="old_splash_enabled">true</bool>
</resources>
5- 在 values-vX 中覆盖 bools.xml(X 是您要应用新 SplashScreen 的最低版本,因此它是 21 到 31 之间的任意数字)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="new_splash_enabled">true</bool>
<bool name="old_splash_enabled">false</bool>
</resources>
6- 在您的 list 中,我让系统根据 bools.xml 文件中的值决定启动哪个启动 Activity
        <activity
android:name=".NewSplash"
android:theme="@style/Theme.App.Starting"
android:enabled="@bool/new_splash_enabled"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".OldSplash"
android:enabled="@bool/old_splash_enabled">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

关于api 21 之前的 Android 12 启动画面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69010523/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com