【问题标题】:Why do API 19 devices (and other devices below API 21) need vectorDrawables.useSupportLibrary to load icons?为什么 API 19 设备(以及 API 21 以下的其他设备)需要 vectorDrawables.useSupportLibrary 来加载图标?
【发布时间】:2020-07-07 15:39:16
【问题描述】:

这个问题我有一段时间了,但我一直在想:为什么我需要申报

vectorDrawables.useSupportLibrary = true

适用于我的 API 19 设备,但不适用于我的 API 29 设备?

它们都加载了我导入的同一个图标,但是为什么 API 19 设备需要声明其他它会给你一个编译时错误。

【问题讨论】:

标签: android android-studio android-gradle-plugin android-vectordrawable


【解决方案1】:

原因是 API 21 (Android 5.0 Lollipop) 中添加了对矢量可绘制对象的原生支持(如内置于 Android 框架中)。

vectorDrawables.useSupportLibrary 选项在 Android 支持库(现在称为 AndroidX AppCompat)中启用了 backward-compatibility feature,允许它在运行时通过 VectorDrawableCompatAnimatedVectorDrawableCompat 类加载矢量可绘制对象。

还可以配置 Android Gradle 插件以在构建时将矢量图像转换为 PNG 文件,以便在 API 21 之前的设备上使用,但这首先会破坏使用矢量可绘制对象的许多好处,例如作为较小的应用程序大小。

【讨论】:

    猜你喜欢
    • 2018-11-14
    • 2017-10-13
    • 2020-10-18
    • 1970-01-01
    • 2016-04-05
    • 2021-11-03
    • 2017-07-21
    • 2016-06-08
    • 2019-01-16
    相关资源
    最近更新 更多