如何为android创建矢量drawable? [英] How to create vector drawables for android?

查看:478
本文介绍了如何为android创建矢量drawable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 VectorDrawables 的新手。

我可以看到android studio提供的默认 vector drawables ,如 ic_menu_gallery ic_menu_camera 等正在发挥作用。所以我尝试通过将 png图像转换为 svg 来创建我自己的向量drawables code>首先使用路径和填充值来制作矢量drawables,即替换 android:pathData 代替d和 android:fillColor 用于svg文件中的填充标记。它以某种方式提供了矢量绘图,但扭曲或曲面看起来。

I can see that the default vector drawables provided with android studio like ic_menu_gallery, ic_menu_camera, etc. are working great. So I tried to create my own vector drawables by converting my png images to svg first and using the path and fill values to make vector drawables i.e replaced the android:pathData for d and android:fillColor for fill tag in svg files. It somehow gave vector drawables but distorted or currputed looking.

如果我没有采取正确的方法,请建议我。

If I am not taking the right approach please suggest me.

推荐答案

您可以使用Android Studio。
将png转换为svg文件在线工具

You can use Android Studio. Convert png to svg file online tools PNG to SVG

对于SVG颜色可以使用:

For SVG color can use :

  <ImageButton
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:id="@+id/button"
    android:src="@drawable/ic_more_vert_24dp"
    android:tint="@color/primary" />

imageView.setColorFilter(getResources().getColor(android.R.color.black), PorterDuff.Mode.SRC_IN);

可以将SVG转换为PNG在线工具:
coolutils

Can convert SVG to PNG online tool: coolutils

将SVG转换为Android drawable:
inloop

Convert SVG to Android drawable: inloop

这篇关于如何为android创建矢量drawable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆