gpt4 book ai didi

android - 如何使用 svg 而不是 png 实现 Android 启动画面?

转载 作者:太空宇宙 更新时间:2023-11-03 12:03:49 49 4
gpt4 key购买 nike

我制作 RN 应用程序。对于我制作的Android版本/drawable/splash_screen.xml 内容如下

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:drawable="@color/gray"/>

<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>

</layer-list>

并在 res/values/styles.xml 中链接到此文件

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
</style>

也在AndoirdManifest.xml中

<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/SplashTheme"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>

这很好用,但我想制作 SVG 文件而不是 PNG (mipmap/ic_launcher)。SVG 文件可能是这样的 https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html(至少没有动画)。如何实现?

最佳答案

Android Studio 中的默认 SVG 导入器工作不太好,因此我建议使用 SVG 到 VectorDrawable 转换器,如 svg2android .

现在我们需要使用 svg2android 生成的代码创建一个可绘制文件。

res/drawable --> new --> drawable resource file --> paste the vector code there

splash_screen.xml 中,我们需要使用向量添加一个项目作为 drawablegravity 设置为 center

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<!-- background with solid color -->
<item android:drawable="@android:color/white"/>

<!-- logo -->
<item
android:drawable="@drawable/your_logo"
android:gravity="center"/>

</layer-list>

-- 编辑(2019 年 12 月)--

正如@petyr 在评论中指出的那样,svg2android 现在已被弃用,但正如@Krisztián 所建议的那样,Respresso Image Converter几乎可以做 svg2android 可以做的所有事情。只需将 SVG 图像添加到其中,将其保留在 auto 中,它将生成一个与 Android 兼容的 SVG。

关于android - 如何使用 svg 而不是 png 实现 Android 启动画面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42595335/

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