3.使用android studio 右键,创建
4.添加生成vector
- 本地SVG,PSD文件
- Name:名称
- Path:本地文件路径
- Size:可以自行调节大小
- Opacity:不透明性
添加进来之后,类似于下面的代码
- android:viewportHeight和android:viewportWidth属性,这个是画布宽高
<vector xmlns:android=“http://schemas.android.com/apk/res/android”
android:width=“50dp”
android:height=“50dp”
android:viewportHeight=“1024.0”
android:viewportWidth=“1024.0”>
<path
android:fillColor=“#BECFDB”
android:pathData=“M0,853.3c0,93.9 76.8,170.7 170.7,170.7h102.4v-85.3H187.7c-56.3,0 -102.4,-47.4 -102.4,-105.4V750.9H0v102.4zM85.3,190.7C85.3,132.7 131.4,85.3 187.7,85.3h85.3V0H170.7C76.8,0 0,76.8 0,170.7v102.4h85.3V190.7zM1024,273.1V170.7c0,-93.9 -76.8,-170.7 -170.7,-170.7h-102.4v85.3h85.3c56.3,0 102.4,47.4 102.4,105.4V273.1h85.3zM938.7,833.3c0,58 -46.1,105.4 -102.4,105.4h-85.3v85.3h102.4c93.9,0 170.7,-76.8 170.7,-170.7v-102.4h-85.3v82.3z”/>
<path
android:fillColor=“#3E96D2”
android:pathData=“M699.7,443.7h-119.5V324.3c0,-37.5 -30.7,-68.3 -68.3,-68.3s-68.3,30.7 -68.3,68.3v119.5H324.3c-37.5,0 -68.3,30.7 -68.3,68.3s30.7,68.3 68.3,68.3h119.5v119.5c0,37.5 30.7,68.3 68.3,68.3s68.3,-30.7 68.3,-68.3v-119.5h119.5c37.5,0 68.3,-30.7 68
.3,-68.3s-30.7,-68.3 -68.3,-68.3z”/>
5.在布局中使用
**注意:使用前需要在app build.gradle中添加andro
资料获取→专栏
id下面的defaultConfig下面添加vectorDrawables.useSupportLibrary = true**
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
直接在ImageView的background中引入该资源即可.
比如下面的代码:
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:drawableStart=“@drawable/ic_add”/>
yout_width=“wrap_content”
android:layout_height=“wrap_content”
android:drawableStart=“@drawable/ic_add”/>