2

Have a look at this Gist.

Above gist creates a drawable which looks like this:

enter image description here

Clearly in the gist, pathData property has been provided coordinates. How is this achieved, I mean, ofcourse someone doesn't found each point according to his needs.

My question : How is this achieved? Is there any tool present to do so?

Drawable like this reduces app size by avoiding to have an image instead. Also, there are questions for drawables in XML like this, this and many more but I think my Question is very different (and useful, probably).

Community
  • 1
  • 1
Shubham A.
  • 2,446
  • 4
  • 36
  • 68
  • use free `inkscape` tool, save your drawing as `*.svg` file, then import it using android studio – pskink Dec 25 '16 at 12:16

2 Answers2

0

You can design your SVG files using some tools such as Android Vector Asset Studio

Usually people don't write the SVG paths themselves, they use a tool or an editor where they sketch the drawing and generate the file.

Mina Wissa
  • 10,923
  • 13
  • 90
  • 158
0

What you have to do is to create a SVG image using an SVG editor such as Inkscape (the one I use) or if you want a more professional (and expensive) editor you can use Adobe Illustrator. You can even use a tool called svg-edit which is accessible in the browser.

After creating your required art, save your SVG file. Next goto and open Android Studio.

  • Right click on the res folder (any folder where drawables are usually placed)
  • Select New > Vector Asset. This opens the following window.

enter image description here

  • Select local file

enter image description here

  • Edit the path to direct it to the location of your svg file
  • Depending on the complexity of your image, errors may be thrown (not all svg elements get converted to xml. Hence, avoid using complex art in svg, use raster images in that case).
  • Android studio does some fixes on its own. So even if errors are thrown, if your image renders fine, then you are good to go.
  • Click Next > adjust a few more settings > Click Finish
  • Your xml vector asset has been created successfully.

Note: To ensure backward compatibility, add the following to your build.gradle

android{
         defaultConfig{
                        vectorDrawables.useSupportLibrary = true
                      }
       }
dependencies{
              compile 'com.android.support:appcompat-v7:23.2.0'
            }

Hope this has helped you. For more info see the official documentation.

Acedev003
  • 51
  • 1
  • 7