Skip to content

pantoken / packages/core/src / toVectorDrawable

函数: toVectorDrawable()

toVectorDrawable(svg, options?): string

Beta

将内联 SVG 转换为 Android VectorDrawable XML 字符串。基于描边的图标(Lucide)会输出 strokeColor/strokeWidth; 基于填充的图标(Custom)会输出 fillColor

参数

svg

string

内联 SVG 标记。

options?

VectorDrawableOptions = {}

VectorDrawableOptions.

返回值

string

VectorDrawable 的 XML。

示例

基于描边(Lucide)的图标会输出 strokeColor

ts
import { toVectorDrawable } from "@pantoken/core";

const xml = toVectorDrawable(
  '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">' +
    '<path d="M5 12h14"/></svg>',
);
// → <vector …> with android:strokeColor and android:pathData="M5 12h14"

带色调的基于填充(Custom)图标会输出 fillColor

ts
import { toVectorDrawable } from "@pantoken/core";

toVectorDrawable('<svg viewBox="0 0 24 24"><path d="M0 0h24v24H0z"/></svg>', {
  color: "#FF0374B5",
});
// → <vector …> with android:fillColor="#FF0374B5"