I'm reading and watching UI tutorial. They all talk about the fact that you need to be aware of different devices size and resolution. Therefore export your icons into several size to support different screen density.
SVG is an open standard (W3C) that should be use to tackle this kind of problem. So can I natively use SVG file as drawable for my icons ?
N.B.: I'm NOT talking about browser support.
Android does not support SVG rasterization. Look at libsvg-android or svg4mobile. It solves that problem.
The answer has changed. Since version 21, Lollipop the operating system has had support for VectorDrawable. This is added to by a support library that allows you to use VectorDrawable well back into previous versions. These include support for importing most of the important SVG vector commands and having Android Studio automatically convert them to a VectorDrawable.
Use Vector Image Assets for all versions. -- Also even in older versions it's entirely possible to do fonts. Basically you give it a font asset then load up a specific letter of the font as an icon. Since fonts are glyphs and vector glyphs at that, you can very much get vector icons pretty far back.
https://fortawesome.github.io/Font-Awesome/icons/
Related
Im attempting to replace all my Android drawable png assets with VectorDrawables.
Where I use the Android Studio standard assets obviously everything is fine.
Some externally imported SVG assets fail as Android does not support the industry-standard SVG specification.
Does an Android vector drawable specification exist?
which lists all acceptable SVG commands that Android (Android Studio) will accept?
As far as I am aware, there is no formal written specification for the VectorDrawable format other than the VectorDrawable class definition in the documentation.
https://developer.android.com/reference/android/graphics/drawable/VectorDrawable
There is also quite a lot of extra information on this page:
https://developer.android.com/studio/write/vector-asset-studio
Neither of these have a list of SVG elements that are supported by the importer. However you can look at the code for the importer in the Android source code for the definitive answer as to what is supported. The source code is here: SVG2Vector.java
From the code, you can see that the supported SVG elements are limited to:
<polygon>, <rect>, <circle>, <line>, <path>, <g>
Note that these are only partially supported, as only a limited set of their attributes are handled. Basically just the stroke and fill related ones, plus transform and display:none.
There are, however, other third-party converters available that claim to do a better job. Although what they can possibly support is limited by what VectorDrawable itself supports.
In iOS development with Xcode it is really convenient because you can add an image asset or launcher icon with one .pdf file and it generates all the necessary sizes automatically. The .pdf file can be created with Adobe Illustrator or a similar program that makes vector graphics.
Rather than sit there and export every size of icon/image asset one at a time, is there a fast way to add a vector image to Android Studio and have it populate all of the relevant sized folders on its own? Or in general, is there a way to accomplish the same thing in some way?
I have seen other posts where people suggest using an online tool that takes your .png image and lets you download a .zip with all of the different image sizes, but by definition, that method will not result in crisp and high quality image assets. You always want to go from a vector.
is there a fast way to add a vector image to Android Studio and have it populate all of the relevant sized folders on its own?
Use File > New > Vector Asset in Android Studio 1.5 and higher. This will let you import an SVG file. Android Studio will attempt to convert it into a vector drawable resource, with varying degrees of success. If you are using a recent version of the Android Plugin for Gradle (1.5.0 or higher should work AFAIK), the build tools will also generate PNGs from the vector drawables for use on older devices (Android 4.4 and earlier).
but by definition, that method will not result in crisp and high quality image assets
You do not have much of a choice on older devices. There are a few deprecated backports of VectorDrawable floating around that you can try to use, but Google abandoned theirs.
You always want to go from a vector.
Not necessarily. Please bear in mind that not everybody has high-end mobile devices. Rendering SVG or other vector artwork is comparatively expensive, which is why Android did not directly support it (and still does not directly support SVG itself).
I mean for example the app icon. I have a icon in vector format. And now I need to create png images for all kinds of dpi. I don't want to do it by hand. I suppose that there should a program for that, because it's easy to automate this task. But I can't find one.
Recent Android Studio v14 does generate raster images for older android versions than lollipop.
I am investing some time doing drawables for an Android project and I am looking for alternatives.
Currently I do them on Adobe Illustrator and with some drawables I can use Android Asset Studio (e.g. drawables for the action menu). The problem with Android Asset Studio is the lack of possibilities to use my own color (we can only use white/black colors).
I wanted something like Android Asset Studio where I can give him a HD image and he creates all drawable sizes. Is that possible?
Another option could be a program/script that could allow me to say "I want to scale to these resolutions" and he does it for all images.
What you're looking for is called a batch resizer, but without knowing what you're working with, it's hard to give a recommendation. For instance, you can use both Photoshop and Gimp for it. I believe Gimp will require a plugin, while Photoshop has the script built-in.
I would like to use more vector drawings in my Android applications. Providing images isn't as space efficient or as scalable as I would like it to be.
Android provides a series of Drawable file formats, such as ShapeDrawable, which can be combined in a LayeredDrawable. To go very far down this path, it would be nice if there was a designer for visualizing the results, doing the drawing in, and handling all the resulting files.
C# WPF has Expression Blend, Adobe has Flash CS4, and the iPhone has Opacity. So my question is, is there a designer or drawing tool for Android?
Note: Other questions have talked about using SVG in Android. Android doesn't have native support for SVG, so the only way to do it is with an external library. I would like to avoid that and am asking for a developer side tool. An SVG to Drawable converter would be fine, but I'm not aware of one.
I faced the same problem and I've just released a little library on github that allow to export svg to drawable more quickly.
https://github.com/r3gis3r/svg2drawable
Hope can be useful for you.
For the sub-subset of rectangular ShapeDrawables there is a nice tool online at Angry Tools which allows one to edit a button's drawable:
http://angrytools.com/android/button/
I would suggest you using Vector Drawables, which are natively supported by Android 5.0+. There is an SVG to VectorDrawable Converter, so you can create SVG images in your favorite editor.
BetterVectorDrawable is the VectorDrawable implementation for Android 4.0+ with configurable fall-back behavior on Android 5.0+.
SVG to VectorDrawable Converter is the batch converter of SVG images to Android VectorDrawable XML resource files. Online version exists.
Links point to readmes, which provide enough information on how to use the lib and the converter.
Yes, there is.
https://play.google.com/store/apps/details?id=com.tiraisoft.drawabledesigner
It runs on Android so you can see the changes live.
Disclaimer:
I'm the author