74

Short of building and installing my app, is there a way to preview a vector drawable xml file?

I've built it into a small test app in Android Studio, and can preview it as part of the layout file, but I was hoping for a simpler way.


Edit: here's what my drawable.xml file looks like:

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24">

    <group>
        <path
            android:fillColor="#f5a625"
            android:strokeColor="#000000"
            android:strokeWidth=".5"
            android:pathData="M0,0l18,0l6,6l0,10l-24,0z" />
    </group>
</vector>
Edward Falk
  • 9,991
  • 11
  • 77
  • 112

7 Answers7

145

There is a Preview tab especial for that at the right side (since Android Studio 2.0):

enter image description here

dasar
  • 5,321
  • 4
  • 24
  • 36
  • This `Preview` tab doesn't exist anymore. The functionality is now integrated within the window itself. You can choose to switch Between `Code`, `Split` and `Design`. However it only shows these buttons if the vector drawable is used in the currently selected build variant. The only way I could see a preview for other build variants, was to switch to that specific build variant. – Wirling Feb 22 '21 at 14:00
16

If the Preview window doesn't automatically show. You can manually show the Preview window by going to View -> Tool Windows -> Preview in Android Studio's menu.

Jade
  • 3,156
  • 1
  • 34
  • 44
15

There is a way to preview all the vector drawables in your project at the same time using the Android Studio plugin at https://plugins.jetbrains.com/plugin/10741-vector-drawable-thumbnails

just go to Settings -> Plugins -> Browse Repositories and search for "Vector Drawable Thumbnails"

Ignacio Tomas Crespo
  • 3,401
  • 1
  • 20
  • 13
3

Android Studio 1.4 lets you preview VectorDrawables. Just double-click on them in your res/drawable folder.

Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181
  • When I do that, I just see the XML. Any idea what I'm missing? – Edward Falk Oct 13 '15 at 17:49
  • It didn't show the preview for me at first either, but by going to another file and then going back to the vector drawable the preview showed up. The tab might also be minimized: look for the 'Preview' tab on the right hand side. – jguerinet Oct 23 '15 at 20:03
  • 1
    it would be nice if it was possible to preview all of them together like in finder/explorer. We often need to search through icons to find the one we need and it's not ideal to double click on each one – Carson Holzheimer Apr 12 '18 at 01:54
3

My solution for this was: right click on the .xml file, then click "Open in Right Split". The preview should appear on the right side of the code.

Chefski
  • 31
  • 2
1

You can quickly search through vector drawable previews in Android Studio by going to design view in the xml editor and under properties, clicking the ... button next to srcCompat

Carson Holzheimer
  • 2,890
  • 25
  • 36
1

When you open the vector drawable in Android Studio, there are controls available in the upper right corner of the window. You can choose to switch between Code, Split and Design.

However these controls only show up if the vector drawable is used in the currently selected build variant. The only way I could see a preview for drawables from other build variants, was to switch to that specific build variant.

android studio controls

Wirling
  • 4,810
  • 3
  • 48
  • 78