Android中VectorDrawableCompat的使用注意事项

  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>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值