如何在低于 21 的 Android API 中使用 VectorDrawables? [英] How to use VectorDrawables in Android API lower than 21?

查看:31
本文介绍了如何在低于 21 的 Android API 中使用 VectorDrawables?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Android 项目,我选择了 来显示图标,因为它具有适应性和动态性,但是,我只能在运行 Android 的设备上运行这个应用程序,它有 API21 或更高.我的问题是如何在较低的 Android 版本(即 API 14 或类似版本)上使用 .谢谢!

I am working on an Android project and I chose <vector> to display icon because it is adaptable and dynamically, however, I just can run this app on devices running Android, which have API 21 or higher. My question is how can I use <vector> on lower Android version i.e. API 14 or kind of. Thanks!

<!-- drawable/ic_android_debug_bridge.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:height="48dp"
    android:width="48dp"
    android:viewportWidth="24"
    android:viewportHeight="24">
    <path android:fillColor="@color/primaryColorDark"
        android:pathData="M15,9A1,1 0 0,1 14,8A1,1 0 0,1 15,7A1,1 0 0,1 16,8A1,1 `0 0,1 15,9M9,9A1,1 0 0,1 8,8A1,1 0 0,1 9,7A1,1 0 0,1 10,8A1,1 0 0,1 9,9M16.12,4.37L18.22,2.27L17.4,1.44L15.09,3.75C14.16,3.28 13.11,3 12,3C10.88,3 9.84,3.28 8.91,3.75L6.6,1.44L5.78,2.27L7.88,4.37C6.14,5.64 5,7.68 5,10V11H19V10C19,7.68 17.86,5.64 16.12,4.37M5,16C5,19.86 8.13,23 12,23A7,7 0 0,0 19,16V12H5V16Z" /></vector>

推荐答案

Vector Drawables 现在向后兼容,只需将您的 gradle 版本升级到 1.4.0-beta3 或更高版本,并升级您的 IDE:

Vector Drawables are now backward compatible, it's just a matter of upgrading your gradle version to 1.4.0-beta3 or higher, and upgrade your IDE :

我们也很高兴为您的载体提供向后兼容性Android Studio 1.4 中的资产.一旦你有一个 vectorDrawable 图像你的 res/drawable,Gradle 插件会自动生成构建时 API 级别 20 及以下的光栅 PNG 图像.这个意味着您只需要更新和维护您的矢量资产应用项目和 Android Studio 可以处理图像转换过程.

We are also excited to offer backwards compatibility for your vector assets in Android Studio 1.4. Once you have a vectorDrawable image in your res/drawable, the Gradle plugin will automatically generate raster PNG images for API level 20 and below during build time. This means you only need to update and maintain your vector asset for your app project and Android Studio can take care of image conversion process.

http://android-developers.blogspot.com.uy/2015/09/android-studio-14.html

这篇关于如何在低于 21 的 Android API 中使用 VectorDrawables?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆