Invalid drawable tag vector

I faced a similar problem and @pedja's own answer is useful. More generally, as mentioned in Chris Banes's article on vector drawable compat, the support library works by injecting its version of ImageView over the system one on pre-L via some hooks. This implicitly requires the AppCompat versions of classes, such as AppCompatActivity, be used.

In my case, the vector drawable is used in a standalone toast-like view without an associated activity, using the Application context. I ended up using AppCompatImageView in the xml layout definition directly, i.e. something like

<android.support.v7.widget.AppCompatImageView
             android:id="@+id/some_id"
             android:layout_width="24dp"
             android:layout_height="24dp"
             android:src="@drawable/selector_referencing_vector_drawable"/>

thus there is no need for the magic "hook" mechanism. As tested this also works with the Activity class without the need of using AppCompatActivity. All the above was done without upgrading to 23.2.1, which addressed a different problem.


This code is going to work with vector if using
vectorDrawables.useSupportLibrary = true

And change android:src to app:srcCompat.

For example,

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/triangle"/>

to

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:srcCompat="@drawable/triangle"/>

Got this problem too when loading vectors from a selector on pre-lollipop devices:

Use AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) in your onCreate method:

Sets whether vector drawables on older platforms (< API 21) can be used within android.graphics.drawable.DrawableContainer resources. When enabled, AppCompat can intercept some drawable inflation from the framework, which enables implicit inflation of vector drawables within android.graphics.drawable.DrawableContainer resources.

protected final void onCreate(Bundle savedInstanceState) {
         AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
         super.onCreate(savedInstanceState);
         ...