- 首先在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" } }
- 在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);
- 在使用的Activity中,添加如下的配置:
static{ AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); }
- 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>
Android中VectorDrawableCompat的使用注意事项
最新推荐文章于 2024-06-11 09:44:17 发布