You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio导入SVG画质丢失及<marker>不支持错误求助

解决方案

1. 定位错误原因

你遇到的<marker>不支持提示存在误导——你提供的SVG代码里并没有<marker>标签,问题出在Android Studio的SVG导入工具对多段路径的解析误判。第二个<path>标签里用M分隔多条水平线的写法,触发了解析器的错误识别。

2. 修正SVG代码

直接调整VectorDrawable代码即可解决问题,核心修改是拆分多段路径:

  • 将包含多条水平线的单个<path>拆分为独立的<path>标签,避免解析混淆
  • 确保路径指令符合Android VectorDrawable语法规范

修改后的完整代码:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="640dp"
    android:height="480dp"
    android:viewportWidth="640"
    android:viewportHeight="480">
    <!-- 红色背景 -->
    <path
        android:fillColor="#bd3d44"
        android:pathData="M0,0h640v480H0" />
    <!-- 拆分后的白色水平线 -->
    <path
        android:strokeWidth="37"
        android:strokeColor="#fff"
        android:pathData="M0,55.3h640" />
    <path
        android:strokeWidth="37"
        android:strokeColor="#fff"
        android:pathData="M0,129h640" />
    <path
        android:strokeWidth="37"
        android:strokeColor="#fff"
        android:pathData="M0,203h640" />
    <path
        android:strokeWidth="37"
        android:strokeColor="#fff"
        android:pathData="M0,277h640" />
    <path
        android:strokeWidth="37"
        android:strokeColor="#fff"
        android:pathData="M0,351h640" />
    <path
        android:strokeWidth="37"
        android:strokeColor="#fff"
        android:pathData="M0,425h640" />
    <!-- 深蓝色矩形 -->
    <path
        android:fillColor="#192f5d"
        android:pathData="M0,0h364.8v258.5H0" />
    <!-- 白色图形 -->
    <path
        android:fillColor="#fff"
        android:pathData="m14,0 l9,27L0,10h28L5,27z" />
</vector>

3. 替换导入方式

跳过Android Studio的SVG导入工具,直接在res/drawable目录下新建.xml文件,粘贴上述代码后同步项目。这种方式能绕过导入工具的解析错误,直接使用兼容的VectorDrawable代码。

4. 验证效果

完成操作后,在Android Studio预览窗口查看该drawable,画质丢失和错误提示的问题会得到解决,显示效果与预期一致。

内容的提问来源于stack exchange,提问作者foseja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 20:21:32