【问题标题】:New Splash screen is shown cut in a cyrcle shape新的初始屏幕显示为圆形切割
【发布时间】:2021-12-21 22:58:00
【问题描述】:

我正在尝试用新的 Splashscreens API 替换我的 Android 应用中基于活动的旧启动画面

所以我创建了我的应用程序徽标的 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);
    ...

【问题讨论】:

    标签: android splash-screen


    【解决方案1】:

    您可以做的是将您的图标包裹在一个可嵌入的可绘制对象中,以便将其绘制在圆圈内。

    例如,创建一个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

    【讨论】:

      【解决方案2】:

      当我在 30 年代的模拟器上运行我的应用程序时会发生这种情况,但是当我在物理设备上运行它时它显示得很好。查看您上面的代码和评论,是否真的需要您从样式/Res 中实现图像?...我建议您在 splash_screen.xml 中创建 imageView

      【讨论】:

      • 我实际上使用的是物理设备,我没有 splash_screen.xml,因为它说直接使用矢量图像
      • 好的.....如果矢量图像一直显示不正确,您也可以尝试将图像导入为 PNG。
      猜你喜欢
      • 1970-01-01
      • 2019-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-17
      • 1970-01-01
      • 2016-12-05
      相关资源
      最近更新 更多