I need to use an icon of a contract on my app.
Usually, I'd create a new Vector Asset and lookup for an icon that might do the job.
Unfortunately, this time I couldn't find anything similar to my needs, so I want to create one!
I tried reading about the issue here but it wasn't really helpful.
can someone tell me how to do that and what is that pathData?
Thanks!
You can create vector assets from SVG sources. If you want to create your own icon, you should probably use a graphics program that can export drawings as SVG. Inkscape for example is free and available for a lot of platforms.
When you have the SVG file, in AndroidStudio select File -> New -> Vector Asset. In the upcoming dialog, select Asset Type 'Local file' and then pick/enter the path to your SVG.
You can download from the web / create by photoshop your own SVG files , once you have .svg file you can add it to your project by right click on app > new > Vector Asset > Local file (SVG,PSD) and use it as you normally use android:src="#drawable/ic_my_icon"
now a pathData is A path that represents the outline of a shape which can be filled or stroked. A path can also be used as a clipping path, to describe animation, or position text.
But for me what really did the job was just playing with the numbers of it and see the reaction of the actual path, what do i mean ?
Check out ShapeShifter and watch this video , drag some .svg files from the web and start playing with it , I'm sure you will get the idea .
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
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 :)
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.
I'm using the instructions found here, from Google to use the new option (March 2016) to import .svg files into drawable instead of .png files.
The problem I have is that the file gets imported as black and white, even though the file has many colors.
Here's an image of the .svg file, as read by Google Chrome:
This same file, is then read like this by the Vector Asset Studio:
And in the app, the image shows up as black and white.
Any idea of why this is happening?
The .svg file is getting generated on Adobe PhotoShop Creative Cloud, and I'm using Android Studio 1.5.1 on Mac.
Thank you!
EDIT: added link to .svg file I'm using for this question.
I also had the same problem but after digging internet
finally found the solution, here it is:-
After getting done with illustrator designing
1) Go to File --> Save As ---> Window Dialog box Opens--> type name of svg
--->Click Save
2) Now it shows SVG Options dialog box ---> At bottom left click More Options ---> In CSS Properties dropdown ---> Select Presentation Attributes
this setting makes svg compatible code for android import with colors !!
Sorry for making this answer elaborate ... did this for those who are beginners
Android Studio's SVG importer is somewhat limited. It only handles very simple SVG files. And I don't believe it supports the <style> element, or the class attribute. So you will need to change the CSS to XML properties.
For example:
<path class="st0" d="M163.3,10.8c2.4-0.5,6.2-0.9,10-0.9c5.5,0,9,0.9,11.6,3.1c2.2,1.6,3.5,4.1,3.5,7.5c0,4.1-2.7,7.7-7.2,9.3v0.1
c4,1,8.7,4.3,8.7,10.6c0,3.6-1.4,6.4-3.6,8.5c-3,2.7-7.7,4-14.6,4c-3.8,0-6.7-0.3-8.5-0.5V10.8z M168.8,28.1h5c5.8,0,9.2-3,9.2-7.1
c0-5-3.8-6.9-9.3-6.9c-2.5,0-4,0.2-4.8,0.4V28.1z M168.8,48.4c1.1,0.2,2.6,0.3,4.6,0.3c5.7,0,10.9-2.1,10.9-8.2
c0-5.8-5-8.2-10.9-8.2h-4.5V48.4z"/>
Will need to be changed to:
<path fill="#007299" d="M163.3,10.8c2.4-0.5,6.2-0.9,10-0.9c5.5,0,9,0.9,11.6,3.1c2.2,1.6,3.5,4.1,3.5,7.5c0,4.1-2.7,7.7-7.2,9.3v0.1
c4,1,8.7,4.3,8.7,10.6c0,3.6-1.4,6.4-3.6,8.5c-3,2.7-7.7,4-14.6,4c-3.8,0-6.7-0.3-8.5-0.5V10.8z M168.8,28.1h5c5.8,0,9.2-3,9.2-7.1
c0-5-3.8-6.9-9.3-6.9c-2.5,0-4,0.2-4.8,0.4V28.1z M168.8,48.4c1.1,0.2,2.6,0.3,4.6,0.3c5.7,0,10.9-2.1,10.9-8.2
c0-5.8-5-8.2-10.9-8.2h-4.5V48.4z"/>
Etcetera for the rest of the <path> elements.
It's so simple
you can change your color directly from your svg xml after adding image to your project .
when you added image to your project; svg color must be like this :
android:fillColor="#000000"
just need to change to this :
android:fillColor="#b3ff856d"
just looking for android:fillColor
I want to recreate my app for iOS and the icons in Android are XML vectors with the "android:pathData" attribute. How do I convert these to an image that I can place into Xcode and use (preserving transparency)?
I have searched for a solution and found nothing and read the article on the Android Developer site on Vector Asset Studio but found nothing about exporting these drawables to something I can import into Xcode.
I did it by creating an SVG file and copying the value of the pathData attribute of the path element in the XML file and pasting it into the d attribute of the path element in the SVG file. I then converted it to PNG using ImageMagick.
So
<path android:pathData="[Path Data]">
becomes
<path d="[Path Data]">.
Then
convert -background none image.svg image.png
in the command line.
If there is a better way of doing this please post it.
After using the trick Questioner provide, I use a browser to open the svg file, zoom-in to the size as big as possible and take a screenshot. FYI.
I want to create a nine-patch image and use that in my App but I don't know how to create it?
I've searched through the Android source code on the Web and I can't seem to find any examples of this. I need a tutorial so that I can understand the process.
I have searched the best and the simplest answer to make 9-patch image. Now to make the 9 patch image is the easiest task.
From HERE you can make a 9-patch image for all the resolutions - XHDPI,HDPI,MDPI,LDPI in just one click.
Let me know if you have any queries, and do upvote it, if it was helpful to you.
I just found that awesome alternative 9patch editor (by Mikle Garin) and I think it 1000% better than standard one built in sdk:
Editor JAR download link
Editor source code
Editor official page
There's a tool included in the android sdk to create and test nine patch images:
http://developer.android.com/guide/developing/tools/draw9patch.html
You can also create a nine patch file using every gfx package out there ( photoshop, paint.net, ... ) using the creation guideline here: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
I've created a tool that allows automatically create 9-patch images from regular PNG images for simple cases where stretchable areas are 1 pixel wide. Here's sample input and output (showed at 400%):
Project page on github
A NinePatch image is a standard PNG image created with Photoshop, Illustrator, Paint... etc.
To add a NinePatch rule to it, just drag/drop it on the draw9patch.bat tool in your Android SDK directory.
IF you don't use the draw9patch.bat tool, you must include an extra 1px transparent border to draw the NinePatch rules with a 1px black (#000000) pencil size before you save it.
Important!!! Save the image with the extension myimage.9.png as a transparent PNG-8/PNG-24.
Image: Explanation of NinePatch graphic rules
http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html
Although android provides the tool for ninepatch images .Open terminal and go to android sdk -tools path and type ./draw9patch. But this is the best link you can make for all density in just one click.