Android 使用SVG矢量图
2017-03-05 16:55
453 查看
下载矢量图
矢量图,是什么,就不用讲了,不清楚,自行百度哈。阿里矢量图库 http://www.iconfont.cn/,这里有各式各样的矢量图,基本能满足我们日常用图需求。
首先,下载*.svg格式的矢量图
Android studio 使用矢量图
项目中,在要放置矢量图的目录右击->new->Vector Asset,如下图开始转换
最后,生成ic_menu_collection.xml矢量图xml文件
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportHeight="1024.0" android:viewportWidth="1024.0"> <path android:fillColor="#FF000000" android:pathData="M895.8,517.7c88.3,-91.9 88.2,-240.9 0,-332.8 -45.1,-47 -104.5,-69.9 -163.6,-68.9 -82.7,1.5 -219,115.4 -219,115.4s-140.2,-115.6 -224.9,-115.4c-57.7,0.1 -115.4,23.1 -159.4,68.9 -88.2,91.9 -88.3,240.9 0,332.8l383.5,399.3L895.8,517.7z" /> </vector>
使用
和图片一样使用即可
代码动态改变SVG顔色
package com.xuewei.utils; import android.content.Context; import android.graphics.drawable.Drawable; import android.support.v4.content.ContextCompat; import android.support.v4.graphics.drawable.DrawableCompat; import android.widget.ImageView; import com.xuewei.XWApplication; /** * * Created by Administrator on 2017/3/11. */ public class SVGUtils { public static SVGUtils svgUtils; private Context mContext; private SVGUtils(){ mContext = XWApplication.getInstance(); } public static SVGUtils getInstance(){ if(svgUtils==null){ svgUtils = new SVGUtils(); } return svgUtils; } /** * 改变SVG图片着色 * @param imageView * @param iconResId svg资源id * @param color 期望的着色 */ public void changeSVGColor(ImageView imageView,int iconResId,int color){ Drawable drawable = ContextCompat.getDrawable(mContext, iconResId); imageView.setImageDrawable(drawable); Drawable.ConstantState state = drawable.getConstantState(); Drawable drawable1 = DrawableCompat.wrap(state == null ? drawable : state.newDrawable()).mutate(); drawable1.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); DrawableCompat.setTint(drawable1, ContextCompat.getColor(mContext, color)); imageView.setImageDrawable(drawable1); } }
调用
if(groupXueWei.getCollection()){ SVGUtils.getInstance().changeSVGColor(holder.collectionIcon,R.drawable.ic_collection,R.color.collection); }else{ SVGUtils.getInstance().changeSVGColor(holder.collectionIcon,R.drawable.ic_collection,R.color.unCollection); }
相关文章推荐
- Android中使用SVG矢量图(一)
- 在AndroidAPP中使用SVG矢量图
- Android使用SVG矢量图打造酷炫动效!
- Android中使用SVG矢量图(一)
- Android使用SVG矢量图打造酷炫动画效果
- Android使用SVG矢量图打造酷炫动效! 以及用ps生成vector
- Android Studio 如何使用SVG矢量图
- Android中使用SVG矢量图打造多边形图形框架
- Android使用SVG矢量图打造酷炫动效!
- svg矢量图绘制以及转换为Android可用的VectorDrawable资源
- Android VectorDrawable SVG矢量图 xml格式
- SVG-Android开源库——项目简单接入与使用
- Android 关于SVG矢量图支持
- android 中使用svg 失量图标
- Android tips(十二)-->Android开发中使用矢量图
- Android SVG动画PathView源码解析与使用教程(API 14)
- Android使用SVG矢量动画(二)
- Android内存控制小技巧-使用矢量图来节省你的内存并简化你的开发。
- Android使用SVG矢量动画(二)
- 通过android studio 支持各版本使用矢量图 (SVG)