Android 12 及以上版本:如何使用系统主题 Theme.splashScreen
要引用到系统的 'Theme.splashScreen' 主题,可以按照以下步骤进行操作:
-
在项目的 'res/values' 目录下创建一个名为 'styles.xml' 的文件(如果已存在则跳过此步骤)。
-
在 'styles.xml' 文件中添加以下代码:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@android:drawable/splash_screen_drawable</item>
</style>
在上述代码中,'AppTheme' 是自定义的主题名称,'Theme.AppCompat.Light.NoActionBar' 是主题的父主题,'android:windowBackground' 用于指定窗口背景,'@android:drawable/splash_screen_drawable' 是系统的 splash screen drawable 的资源 ID,可以根据自己的需要进行更改。
- 在 'AndroidManifest.xml' 文件中的 '
' 标签下添加 'android:theme' 属性,将其值设置为 '@style/AppTheme',如下所示:
<application
...
android:theme="@style/AppTheme">
...
</application>
这样就成功引用了系统的 'Theme.splashScreen' 主题。请注意,'Theme.splashScreen' 是 Android 12 及以上版本引入的主题,因此如果您的应用程序目标设备版本较低,此主题可能不可用。
原文地址: https://www.cveoy.top/t/topic/qqoC 著作权归作者所有。请勿转载和采集!