一、让Android支持VectorDrawable
apply plugin: 'com.android.application' android { defaultConfig { vectorDrawables.useSupportLibrary = true } } dependencies { compile 'com.android.support:appcompat-v7:25.1.1' }
二、显示VectorDrawable
1、ImageView,直接用
<ImageView android:layout_width="100dp" android:layout_height="100dp" app:srcCompat="@drawable/ic_mic_none_black_24dp" />
2、Button等有状态的,用:
<Button android:layout_width="100dp" android:layout_height="100dp" android:background="@drawable/bg_btn" /> //bg_btn: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/ic_mic_none_black_24dp" android:state_pressed="true" /> <item android:drawable="@drawable/ic_mic_black_24dp" /> </selector>
并在Activity中开启:
static { AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); }