【发布时间】:2023-03-29 23:15:02
【问题描述】:
我想在 Android Studio 中使用 svg drawable。我使用drawable->New->Vector Asset->Local File,但它不导入我的svg文件。我用svg2android 试试这个文件,它会抛出一些警告。
警告 #1:在路径上一次或多次未找到笔划宽度。将所有实例默认为 1。 警告 #2:不支持路径上的转换,请使用选项烘焙转换为路径
生成的xml文件如下:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportWidth="100"
android:viewportHeight="100">
<path
android:strokeColor="#66899a"
android:strokeWidth="1"
android:pathData="M 0 -44 C 3.31370849898 -44 6 -24.3005289926 6 0 C 6 24.3005289926 3.31370849898 44 0 44 C -3.31370849898 44 -6 24.3005289926 -6 0 C -6 -24.3005289926 -3.31370849898 -44 0 -44 Z" />
<path
android:strokeColor="#e1d85d"
android:strokeWidth="1"
android:pathData="M 0 -44 C 3.31370849898 -44 6 -24.3005289926 6 0 C 6 24.3005289926 3.31370849898 44 0 44 C -3.31370849898 44 -6 24.3005289926 -6 0 C -6 -24.3005289926 -3.31370849898 -44 0 -44 Z" />
<path
android:strokeColor="#80a3cf"
android:strokeWidth="1"
android:pathData="M 0 -44 C 3.31370849898 -44 6 -24.3005289926 6 0 C 6 24.3005289926 3.31370849898 44 0 44 C -3.31370849898 44 -6 24.3005289926 -6 0 C -6 -24.3005289926 -3.31370849898 -44 0 -44 Z" />
<path
android:strokeColor="#4b541f"
android:strokeWidth="1"
android:pathData="M 0 -44 C 24.3005289926 -44 44 -24.3005289926 44 0 C 44 24.3005289926 24.3005289926 44 0 44 C -24.3005289926 44 -44 24.3005289926 -44 0 C -44 -24.3005289926 -24.3005289926 -44 0 -44 Z" />
android 是否完全支持 svg?如果是,我该如何导入这个文件?另外,我想以编程方式设置背景可绘制。是否可以不使用 R.drawable.svgXml?我可以从 xml 生成位图吗?
【问题讨论】:
-
android 是否完全支持 svg?不,它有一些限制,它不支持某些 SVG 属性,例如您遇到的那些。尝试寻找其他在线工具将其转换为与 android 兼容。
-
什么警告??可以寄吗?
标签: android svg background-image