title: How to use VectorDrawableCompat from the AppCompat library?
body: <p>I initially wrote this SSCCE with a <code>minsdkversion</code> of <code>21</code> (Lollipop), and it worked fine. <em>But my need is to use a <code>VectorDrawableCompat</code> in pre-lollipop.</em> In the SSCCE, there is an <code>ImageView</code> in the XML layout, in which the source of the image is a vector graphic defined in <code>res/drawable/</code> directory.</p>
  
  <p>Initially, when <code>minsdkversion</code> was set to <code>21</code> in manifest, I used <code>android:src="@drawable/vector_circle"</code> to set the vector graphic as the source of the image in <code>ImageView</code>. This worked fine.</p>
  
  <p>Then I changed <code>minsdkversion</code> in manifest file to <code>11</code>. I also changed <code>ImageView</code>'s <code>android:src="@drawable/vector_circle"</code> attribute to <code>app:srcCompat="@drawable/vector_circle"</code> in XML layout. <strong>But I am getting</strong></p>
  
  <pre><code>Unexpected namespace prefix "app" found for tag ImageView
  </code></pre>
  
  <p><strong>on <code>app:srcCompat="@drawable/vector_circle"</code> line. How should I fix this?</strong></p>
  
  <p><strong><em>SSCCE:</em></strong></p>
  
  <p><strong>res/drawable/vector_circle.xml:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;vector xmlns:android="http://schemas.android.com/apk/res/android" 
       android:width="465dp"
       android:height="420dp"
       android:viewportHeight="600"
       android:viewportWidth="600" &gt;
  
      &lt;group&gt;
  
          &lt;path android:strokeColor="#2196F3"
              android:strokeWidth="2"
              android:pathData="M150,10 L75,200 L225,200 Z" /&gt;
  
      &lt;/group&gt;
  
  &lt;/vector&gt;
  </code></pre>
  
  <p><strong>activity_main:</strong></p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_gravity="center" &gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          app:srcCompat="@drawable/vector_circle" /&gt;&lt;!-- app:srcCompat="@drawable/vector_circle" --&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p><strong>MainActivity.java:</strong></p>
  
  <pre><code>public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong><em>EDIT:</em></strong></p>
  
  <p>I changed <code>res/layout/activity_main.xml</code>'s <code>ImageView</code> element to</p>
  
  <pre><code>&lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          app:srcCompat="@drawable/vector_circle"
          tools:ignore="MissingPrefix" /&gt;
  </code></pre>
  
  <p>I also added <code>layout-v21/activity_main.xml</code> to the <code>res/</code> directory:</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_gravity="center" &gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/vector_circle" /&gt;&lt;!-- app:srcCompat="@drawable/vector_circle" --&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>and added the <code>xmlns:tools="http://schemas.android.com/tools"</code> to <code>FrameLayout</code> element. </p>
  
  <p><strong>The pre-compilation error went away. But when I run the app on Lollipop device, the vector graphic is drawn perfectly fine, but if I run the app on a pre-lollipop device, the application does not fail, but the vector graphic is not drawn at all.</strong> </p>