Skip to content

pantoken / packages/core/src / toVectorDrawable

Hàm: toVectorDrawable()

toVectorDrawable(svg, options?): string

Beta

Chuyển một SVG nội tuyến thành chuỗi XML VectorDrawable cho Android. Các biểu tượng dựa trên nét vẽ (Lucide) phát sinh strokeColor/strokeWidth; các biểu tượng dựa trên tô (Custom) phát sinh fillColor.

Tham số

svg

string

Mã SVG nội tuyến.

options?

VectorDrawableOptions = {}

VectorDrawableOptions.

Trả về

string

XML VectorDrawable.

Các ví dụ

Một biểu tượng dựa trên nét vẽ (Lucide) phát sinh 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"

Một biểu tượng dựa trên tô (Custom) với màu tint phát sinh 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"