title: Android: How to load a vector drawable image into a webview?
body: <p>Sorry if this is a repeat but I searched diligently and didn't find this question asked yet...</p>
  
  <p>So back in ye olden days of Android, you could just add something like this to a WebView's source html:</p>
  
  <pre><code>&lt;img src='file:///android_res/drawable/my.png'/&gt;
  </code></pre>
  
  <p>And it would display my.png correctly in the WebView.  But-- Android now supports (and prefers we use) these new-fangled <a href="https://developer.android.com/reference/android/graphics/drawable/VectorDrawable.html" rel="nofollow">vector drawables</a>, and Android Studio's <a href="http://developer.android.com/tools/help/vector-asset-studio.html" rel="nofollow">Vector Asset Studio</a> makes it really easy to import them from SVG files or whatever.</p>
  
  <p>The great thing is that for backwards compatibility, .pngs are automatically generated during the build for various dpi/screen sizes to support older devices.  So if you're targeting an older device, there are .png images there.</p>
  
  <p>If only I could reach them.  Because, as far as I can tell, using vector graphics <em>does</em> break those <code>file:///android_res/drawable/</code> <code>img</code> links in WebViews.  Which is weird, because as I say there are .png files to see, if it only looked.</p>
  
  <p>I've thought about a few methods to fix this, but none have worked:</p>
  
  <ol>
  <li><p>Since .pngs are generated on-the-fly and are included in the .apk, I thought maybe I could point directly to one of the generated files with something like <code>file:///android_res/drawable-hdpi-v4/my.png</code>.  (I checked the .apk file and that's where one of them was..)   But no such luck there.  Broken image.</p></li>
  <li><p>Okay, I thought-- maybe there's a way to get the WebView to display the vector objects directly.  That is, maybe the WebView would recognize an <code>&lt;img src="file:///android_res/drawable/my_image.xml"/&gt;</code> or something similar.  I mean, Chrome can render svg right?  Maybe it supports the .xml vector format too.  But no dice here either.  (Even if it had worked, it would be unlikely to support older pre-chromium webview versions.)</p></li>
  <li><p>The third thing I tried is to include just one xxxhdpi-sized .png in <code>res/drawable</code> so that the webview would find it and hopefully display it.  Unfortunately, this doesn't work either.  It appears that just having an .xml vector in <code>/drawable</code> is enough to have it block the png, no matter if it's in the <code>/drawable</code> or <code>/drawable-xxxhdpi</code> directories.</p></li>
  </ol>
  
  <p>So the obvious question:  Is there a way to get the WebView to either display the vector xml (or the associated support .png that was generated)?  How do we access drawables from HTML in a WebView w/Vector drawables?  Esp. without having to do anything programmatically?</p>
  
  <p>Anyone know how this is supposed to work?  I guess the next thing to do is delve into the chromium/android source to try to find out how <code>file:///android_res/drawable/</code> works, but that doesn't sound fun, so if anyone has an answer, that would be helpful.</p>
  
  <p>I'm probably missing something really obvious here.  Thx in advance!</p>
  
  <p>Update:  Other things I tried/ruled out include (1) removing underscores in image names (as I thought they might be replaced with "/"), (2) various permutations of baseurl in <a href="http://developer.android.com/reference/android/webkit/WebView.html#loadDataWithBaseURL" rel="nofollow">loadDataWithBaseUrl()</a></p>