【发布时间】:2021-12-22 01:53:36
【问题描述】:
我正在尝试添加一个启动画面,我执行了以下步骤,它适用于 android 11
- 添加了实现
- 将 compileSDKVersion 更改为 31
- 做了一个分层列表
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/black" />
</shape>
</item>
<item
android:gravity="center"
android:drawable="@drawable/ic_my_splash_icon">
</item>
</layer-list>
- 在我的主题中嵌入分层列表
<style name="SplashTheme" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/black</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/splash_icon</item>
<item name="postSplashScreenTheme">@style/Theme.AppTheme</item>
</style>
- 将清单主题更改为 SplashTheme
- 将 installSplashScreen() 添加到 MainActivity
这非常适合 Android 11 API 30 但是图像被拉伸不成比例,并且在 Android 12 API 31 的 icon circle 内被裁剪,我的图标是一个矩形字设计。
我阅读了建议在分层列表的项目中添加位图的答案之一,但是在添加位图后,图标不会在 android studios 的设计视图中呈现,并且我在运行应用程序时只会出现黑屏。
<item>
<bitmap
android:gravity="center"
android:drawable="@drawable/ic_my_splash_icon"/>
</item>
而且我不允许手动输入比例尺寸以使其看起来更好。
【问题讨论】:
标签: android splash-screen