24.2兼容性处理
开始只能在Android5.0+系统上使用Vector功能,Android gradleplugin 1.5发布以后,Androidbuild tools 提供了一种解决兼容性的方案:
如果编译的版本是5.0之前的版本,那么build tools 会把VectorDrawable生成对应的png图片,这样在5.0以下的版本则使用的是生成的png图。
在5.0以上的版本中使用VectorDrawable。
在build.gradle添加generatedDensities配置,可以配置生成的png图片的密度。
从AppCompat23.2开始,Vector可以使用于Android 2.1以上的所有系统,只需要引用com.android.support:appcompat-v7:23.2.0以上的版本就可以了,加入了向下兼容的库:VectorDrawableCompat和AnimatedDrawableCompat。
具体Gradle代码,使用Gradle Plugin2.0以上:
android{
defaultConfig {
vectorDrawables.useSupportLibrary =true
//只生成密度为mdpi的png图片
//vectorDrawables.generatedDensit

本文介绍了如何处理Android应用中VectorDrawable的兼容性问题。通过Android build tools的配置,可以在Android 5.0以下版本将VectorDrawable转换为PNG图片。同时,从AppCompat 23.2开始,通过引入相应的支持库,可以实现对Android 2.1及以上系统的全面兼容。在Gradle配置中设置vectorDrawables.useSupportLibrary为true,并引用com.android.support:appcompat-v7的相应版本,确保使用AppCompatActivity。
订阅专栏 解锁全文
4933

被折叠的 条评论
为什么被折叠?



