新的启动画面显示为圆形

New Splash screen is shown cut in a cyrcle shape

我正在尝试用新的 Splashscreens API

替换 Android 应用程序中基于 activity 的旧启动画面

所以我创建了我的应用程序徽标的 svg,创建了主题,并在我的 MainActivity 中设置了 installSplashScreen 但是当应用程序启动时,启动画面中的徽标看起来像这样:

我该如何解决这个问题?

这是我所做的 style.xml:

<style name="Theme.App.Starting" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/colorAccent</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_visual_vector</item>
    <item name="postSplashScreenTheme">@style/AppTheme</item>
</style>

清单:

<activity
    android:name=".MainActivity"
    android:theme="@style/Theme.App.Starting"
    android:screenOrientation="portrait"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

主要活动:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SplashScreen.installSplashScreen(this);
    setContentView(R.layout.activity_main);
    ...

This happens when I run my app on an emulator 30s but when I run it on a physical device it show well. Looking at your code and comment above, is it really required you implement the image from the styles/Res ?... I recommend you create the imageView in your splash_screen.xml

你可以做的是将你的图标包裹在一个 inset drawable 中,这样它就被绘制在圆圈内。

例如,创建一个drawable/splash_inset.xml资源:

<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/ic_visual_vector"
    android:insetLeft="72dp"
    android:insetRight="72dp"
    android:insetTop="72dp"
    android:insetBottom="72dp"/>

实际的插入值取决于您的图像及其纵横比,这里以所有边缘上的 72dp 为例。

然后将此可绘制对象应用为您的 windowSplashScreenAnimatedIcon