Android中VectorDrawableCompat的使用注意事项

来源:互联网 发布:淘宝卖家如何上传宝贝 编辑:程序博客网 时间:2024/06/10 07:31
  1. 首先在APP的Gradle配置文件中加入如下配置:
    在Gradle2.0:android {  defaultConfig {    vectorDrawables.useSupportLibrary = true  }}在Gradle1.5中:android {  defaultConfig {    // Stops the Gradle plugin’s automatic rasterization of vectors    generatedDensities = []  }  // Flag to tell aapt to keep the attribute ids around  aaptOptions {    additionalParameters "--no-version-vectors"  }}

  2. AppCompatImageView或者ImageView中使用时需如下使用:
    <ImageView    android:layout_width="wrap_content"    android:layout_height="wrap_content"    app:srcCompat="@drawable/ic_search"/>或者ImageView iv = (ImageView) findViewById(...);iv.setImageResource(R.drawable.ic_search);

  3. 在使用的Activity中,添加如下的配置:
    static{AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);}

  4. SVG的导入
    使用插件Vector Asset导入,导入后,位置在Drawable下面,文件实例如下:<vector xmlns:android="..."        android:width="24dp"        android:height="24dp"        android:viewportWidth="24.0"        android:viewportHeight="24.0"        android:tint="?attr/colorControlNormal">    <path        android:pathData="..."        android:fillColor="@android:color/white"/></vector>

0 0
原创粉丝点击