Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do you use svg in drawable folder?

Tags:

android

svg

i am creating a bottom navigation bar for a android app following this guide

however, when using svg in android:icon and building it, it shows a error

Error: The file name must end with .xml or .png

i found out that i needed to move the svg to the assets folder. but if i move it, i can't use the svg... any help is much appreciated, thank you

like image 911
wolnavi Avatar asked Jul 06 '18 15:07

wolnavi


People also ask

Can I use SVG for Android app icon?

If you want to use some icons that are not present in the list of predefined icons, then you can add your own icon by selecting the Asset Type as Local File(SVG, PSD) and then select the path of your file by clicking on Path. After that click on Next > Finish. Now your icon will be added to your res/drawable folder.

How do I add a file to drawable?

Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import. Figure 3: Select Import Drawables from the dropdown menu.


2 Answers

The answer above gives a link to convert pictures from SVG to XML, but this tool is not for free(only for one SVG file)

So why not to use ANDROID build-in tool?

The best way is to go to res-> drawable-> Vector Asset -> Local file (SVG, PSD) ->select your SVG file from the place you save it.
and you are done :)

like image 62
batsheva Avatar answered Sep 17 '22 17:09

batsheva


Android uses vector drawables which are xml files rather than SVG's.

You will have to convert the SVG to a vector drawable. Many ways of doing it but a handy web tool is available here.

It won't do complex SVG's but copes with the majority.

like image 34
CodeChimp Avatar answered Sep 17 '22 17:09

CodeChimp