我正在使用带有SVG2VectorDrawable的Android Studio 2.0:
如果我从\RAW
资源文件夹打开一个svg文件进行编辑,我用红色加下划线的文件和一个警告信息“必须声明元素svg”如下所示:
我该怎么做才能解决这个问题?
我正在使用SVG插件仅用于允许正确查看SVG XML格式的编辑器扩展
这是svg文件的内容:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Livello_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="9.693px" height="22.8px" viewBox="0 0 9.693 22.8" enable-background="new 0 0 9.693 22.8" xml:space="preserve">
<path fill-rule="evenodd" clip-rule="evenodd" fill="#616161" d="M7.703,14.038c1.248,0.911,1.99,2.36,1.99,3.916
c0,2.677-2.17,4.847-4.847,4.847C2.17,22.8,0,20.63,0,17.954c0-1.555,0.743-3.006,1.99-3.916V2.856C1.99,1.281,3.271,0,4.846,0
c1.577,0,2.856,1.279,2.856,2.856C7.702,6.583,7.702,10.311,7.703,14.038L7.703,14.038z M4.769,11.374h1.115V9.616H4.769V8.983
h1.115V7.225H4.769V6.593h1.115V4.834H4.769V4.202h1.115V2.856c0-0.573-0.464-1.037-1.037-1.037c-0.573,0-1.037,0.468-1.037,1.037
v11.42c0,0.47-0.223,0.885-0.618,1.142c-0.855,0.559-1.373,1.508-1.373,2.536c0,1.673,1.355,3.028,3.027,3.028
c1.673,0,3.028-1.355,3.028-3.028c0-1.027-0.517-1.976-1.373-2.536c-0.396-0.258-0.618-0.667-0.618-1.142v-2.27H4.769V11.374
L4.769,11.374z M4.899,20.528c0.132,0,0.239-0.108,0.239-0.239l0-0.478c0-0.132-0.108-0.239-0.239-0.239
c-0.666,0-1.207-0.54-1.207-1.206c0-0.131-0.107-0.239-0.239-0.239H2.976c-0.131,0-0.239,0.108-0.239,0.239
C2.736,19.56,3.705,20.528,4.899,20.528z"/>
</svg>
如以下链接所述,您不能直接在项目中使用.svg
文件。首先需要将它们转换为相应的xml文件。为此,您可以使用Vector Asset Studio。这是这些链接
和
Importing svg file in Android Studio
如果你缺少它所需的jar文件,你可以从这里获得它以及教程
UPDATE
我现在明白了这个错误的真正问题。直接将svg文件复制到项目中时会发生此错误。为了能够正确使用svg,您需要将其作为矢量资源导入。