title: Tint Android vector menu icons through XML
body: <p>I've read answers and blog posts explaining VectorDrawables in Android and how they can be used instead of PNG files of different pixel densities.</p>
  
  <p>I've seen that there is an <code>android:tint</code> XML attribute that can be used on <code>ImageButton</code>s and similar <code>View</code>s, but I want to be able to apply a tint to vector icons I use as menu items, as you are unable to use <code>android:tint</code> on menu items.</p>
  
  <p><a href="http://www.murrayc.com/permalink/2014/11/11/android-changing-action-icon-colors-with-android-5-0s-drawable-tinting/" rel="noreferrer">One blog post</a> explained that tinted drawables can be created like so:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;bitmap
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:src="@drawable/ic_action_something"
      android:tint="@color/color_action_icons_tint"/&gt;
  </code></pre>
  
  <p>where the XML file above is the tinted drawable, the referenced drawable through <code>src</code> is the original vector (black), and the <code>tint</code> is the colour that the icon will be tinted to.</p>
  
  <p>However, the above did not work for me, giving me the following error:</p>
  
  <pre><code>android.content.res.Resources$NotFoundException: File res/drawable/ic_chevron_left_white_24dp.xml from drawable resource ID #0x7f02007e
      at android.content.res.Resources.loadDrawableForCookie(Resources.java:3735)
      at android.content.res.Resources.loadDrawable(Resources.java:3603)
      at android.content.res.Resources.getDrawable(Resources.java:1852)
      at android.content.Context.getDrawable(Context.java:408)
      at android.support.v4.content.ContextCompatApi21.getDrawable(ContextCompatApi21.java:26)
      at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:352)
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:181)
      at ...
   Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: &lt;bitmap&gt; requires a valid src attribute
      at android.graphics.drawable.BitmapDrawable.updateStateFromTypedArray(BitmapDrawable.java:761)
      at android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:726)
      at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1150)
      at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1063)
      at android.content.res.Resources.loadDrawableForCookie(Resources.java:3719)
      at android.content.res.Resources.loadDrawable(Resources.java:3603) 
      at android.content.res.Resources.getDrawable(Resources.java:1852) 
      at android.content.Context.getDrawable(Context.java:408) 
      at android.support.v4.content.ContextCompatApi21.getDrawable(ContextCompatApi21.java:26) 
      at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:352) 
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193) 
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:181) 
      at ...
  </code></pre>
  
  <hr>
  
  <p><strong>Edit:</strong> This is my drawable <code>ic_chevron_left_white_24dp.xml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;bitmap
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:src="@drawable/ic_chevron_left_black_24dp"
      android:tint="@color/white"/&gt;
  </code></pre>
  
  <p>Both the above file, and the referenced one exist.</p>
  
  <hr>
  
  <p>Furthermore, with the above, my IDE (Android Studio) displays this warning:</p>
  
  <blockquote>
    <p>Rendering Problems :  requires a valid 'src' attribute</p>
  </blockquote>
  
  <p>This leads me to the question - how can I tint an XML vector drawable menu icon?</p>
  
  <p>I am aware I can create a copy of the vector and change the <code>fillColor</code> attribute to the colour I want, but apart from this, is there a way to do it non-programmatically?</p>