我制作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 (至少没有动画)。 怎么做到这一点?
答案 0 :(得分:5)
Android Studio中的默认SVG导入程序效果不佳,所以我建议使用SVG到VectorDrawable转换器,如svg2android。
现在我们需要使用svg2android生成的代码创建一个可绘制文件。
res / drawable - &gt;新的 - &gt;可绘制资源文件 - &gt;将矢量代码粘贴在那里
在splash_screen.xml
我们需要使用矢量添加项目
设为drawable
,gravity
设置为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>
答案 1 :(得分:0)
在xml文件中,您只需要使用属性drawable而不是位图标记
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/gray"/>
<item android:drawable="@mipmap/ic_launcher"/>
</layer-list>
答案 2 :(得分:-1)
您好,您可以通过以下方式将svg导入项目:
现在您可以像这样引用drawable
<item
android:drawable="@color/off_white"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/yoursvg"/>
</item>
在此之后你应该能够在屏幕上看到你的形象。如果有帮助,请测试并接受它作为答案。