I use Android Studio 2.0 and support VectorDrawable
library.
My gradle:
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 8
vectorDrawables.useSupportLibrary = true
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
But when I try to load icon in menu on old device:
MenuItem miSubjects = menu.add(R.id.menu_navigation, ACTION_SUBJECTS_ID, order, R.string.action_subjects);
miSubjects.setIcon(ContextCompat.getDrawable(this, R.drawable.ic_labels_gray_24dp));
Icon is a vector but AndroidStudio must generate and drawable for old versions (raster drawable). If it isn't so when how I need to use it?
Vector example ic_labels_gray_24dp.xml
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#8a000000"
android:pathData="m15.316,4.5 l-10.316,0.008c-1.169,-0 -2,0.96 -2,2v5.984c0,1.043 0.78,2 2,2l10.316,0.008c0.991,0 0.968,0.014 1.543,-0.6l4.141,-4.4 -4.141,-4.4c-0.594,-0.594 -0.552,-0.6 -1.543,-0.6zM20.019,13.459 L18.316,15.269c-0.284,0.303 -0.614,0.743 -1.354,1.027 -0.741,0.285 -1.161,0.203 -1.646,0.203h-0.002l-10.316,-0.008c-0.74,0 -1.413,-0.225 -1.998,-0.578v1.578c0,1.043 0.78,2 2,2l10.316,0.008c0.991,0 0.968,0.014 1.543,-0.6l4.141,-4.4 -0.98,-1.041z"/>
</vector>
P.S. It wrote a simple class. It doesn't fix Android Studio bug but at least app will not crash. Maybe someone else has same problem.
public final class VectorDrawable {
private VectorDrawable() {}
public static Drawable getDrawable(Context context, final int id) {
return VectorDrawableCompat.create(context.getResources(), id, context.getTheme());
}
}