Android svg app icon

Android svg app icon

You have no collections yet

All collections displayed here

What can I do with my collections?

Click on any icon you’d like to add to the collection.

Organize your collections by projects, add, remove, edit, and rename icons.

Use the «Paint collection» feature and change the color of the whole collection or do it icon by icon.

Download your collections in the code format compatible with all browsers, and use icons on your website.

Save a backup copy of your collections or share them with others- with just one click!

You have reached your collections limit. Upgrade to get unlimited collections

Register and create new collections

Are you sure you want to delete this collection?

We are sorry you canceled your Premium subscription

You can still enjoy Flaticon Collections with the following limits:

  • You can choose only 3 collections to keep
  • You can only add up to 100 icons per collection
  • You cannot add Premium icons to your collection
The advantages of your collections changed
  • You can choose only 3 collections to keep
  • You can only add up to 100 icons per collection
  • You cannot add Premium icons to your collection

Keep making the most of your icons and collections

Get 20% OFF our
Annual Premium Plan

Источник

What are best practices for using SVG icons on Android?

I am about to create my first Android native (so not browser based) app and looking for some good practices regarding icon creating/provisioning. Since it should support multiple devices/resolutions I thought it is best to use SVG to create them. There is at least this lib: http://code.google.com/p/svg-android/ that promises to offer support for SVG on Android.

So far, I have not found resources describing the usage of this or another library as a means to render SVG Icons on the device, so I am a bit reluctant in using it. The best I have seen so far is using SVG as the source format for pre-rendering png based icons in different resolutions.

So my questions is: Are SVG icons a good option to use directly on the device without a png pre-rendering step (does it work at all), and if, why does nobody seem to use this approach?

12 Answers 12

From Lollipop (API 21) onwards, Android defines the VectorDrawable class, for defining drawables based on vector graphics. Android Studio 1.4 adds the «Vector Asset Studio» to make them easier to work with, including an SVG import feature and a new Gradle plugin that generates PNG versions of VectorDrawable icons at build time for API 20 and earlier. There’s also a third-party tool for converting SVGs to VectorDrawables. Bear in mind that although vector drawables can be defined in XML, the file format is not SVG and not all SVG files can be successfully converted. Simple graphics like icons should work OK.

Читайте также:  Weekend warriors mod ufc android

If you still need to generate PNGs yourself, you’ll need to generate your icons at various resolutions. For ease of generating those PNGs I design icons as SVG and then export to the various sizes using Inkscape which is free and cross-platform. It’s got some nice features for designing icons, including the Icon Preview view (see below), and it generates nice crisp PNGs.

For Android older than Lollipop, your best practice for SVG on Android is going to be to use a tool to convert your SVG to PNG at the size(s) you’re interested in. Existing SVG support for Android is not comprehensive of what you’re likely to find in an SVG file, and even if it were, the support is not built into the OS so using them directly for icons is definitely out.

Beginning with Lollipop (API 21) see What are best practices for using SVG icons on Android?. Thanks to @MarkWhitaker @AustynMahoney for pointing this out.

This is what we are using to transform a SVG file into multiple resolutions. For example, to generate the launch icon: svg2png -w48 icon.svg

Good news everyone! Since android support library 23.2 we can use svg-s till back to API level 7!

If you wanna be compatible backwards only till Lollipop (API 21) check Mark Whitaker’s answer, but if you want to go below you need to add these lines to your build.gradle:

Also keep in mind that:

  • instead of android:src you need to use the app:srcCompat attribute in ImageViews.
  • you cannot use svg-s in StateListDrawables or other xml drawables, create them programmatically instead.
  • you cannot use the android:background attribute or View.setBackgroundResource() function, use the View.setBackground() instead.
  • you cannot use svg-s in case of Notifications.

Since nacho-coloma‘s answer helped me, I’ve taken his excellent script and made it slightly easier to use on a daily basis.

  1. Create directory drawable-svg next to your res directory.
  2. Place your svg files and this script in drawable-svg .
  3. Make the script executable.
  4. Run it. In Ubuntu you can simply double-click it in Nautilus and make it run in a terminal.
Читайте также:  Как раздать пароль от wifi андроид

And later when you get new svg files:

  1. Place new svg files in drawable-svg and run the script again.

By default it will do what you want: Scale every svg file into png files and put them into ../res/drawable-mdpi , ../res/drawable-hdpi etc.

The script takes two parameters:

  1. The svg file pattern to scale, default: *.svg
  2. The base directory for put, default ../res/ (i.e. your res directory with the above mentioned setup).

You can experiment by scaling a single svg into pngs in the current directory like this:

Or simply process all images:

I guess you could place the drawable-svg inside the res directory, but I haven’t looked into what gets wrapped up in the final APK. Also, my svg files have — in their names, which Android doesn’t like, and my script takes care of renaming the png files to something valid on Android.

I’m using ImageMagick for the conversion which is slightly more standard that Inkscape (though I liked the approach). Both methods are included in the script for reference.

Источник

Android svg app icon

You have no collections yet

All collections displayed here

What can I do with my collections?

Click on any icon you’d like to add to the collection.

Organize your collections by projects, add, remove, edit, and rename icons.

Use the «Paint collection» feature and change the color of the whole collection or do it icon by icon.

Download your collections in the code format compatible with all browsers, and use icons on your website.

Save a backup copy of your collections or share them with others- with just one click!

You have reached your collections limit. Upgrade to get unlimited collections

Register and create new collections

Are you sure you want to delete this collection?

We are sorry you canceled your Premium subscription

You can still enjoy Flaticon Collections with the following limits:

  • You can choose only 3 collections to keep
  • You can only add up to 100 icons per collection
  • You cannot add Premium icons to your collection
The advantages of your collections changed
  • You can choose only 3 collections to keep
  • You can only add up to 100 icons per collection
  • You cannot add Premium icons to your collection

Keep making the most of your icons and collections

Get 20% OFF our
Annual Premium Plan

Источник

Android svg app icon

You have no collections yet

Читайте также:  Как сделать чтобы компьютер увидел андроид

All collections displayed here

What can I do with my collections?

Click on any icon you’d like to add to the collection.

Organize your collections by projects, add, remove, edit, and rename icons.

Use the «Paint collection» feature and change the color of the whole collection or do it icon by icon.

Download your collections in the code format compatible with all browsers, and use icons on your website.

Save a backup copy of your collections or share them with others- with just one click!

You have reached your collections limit. Upgrade to get unlimited collections

Register and create new collections

Are you sure you want to delete this collection?

We are sorry you canceled your Premium subscription

You can still enjoy Flaticon Collections with the following limits:

  • You can choose only 3 collections to keep
  • You can only add up to 100 icons per collection
  • You cannot add Premium icons to your collection
The advantages of your collections changed
  • You can choose only 3 collections to keep
  • You can only add up to 100 icons per collection
  • You cannot add Premium icons to your collection

Keep making the most of your icons and collections

Get 20% OFF our
Annual Premium Plan

Источник

Android svg app icon

You have no collections yet

All collections displayed here

What can I do with my collections?

Click on any icon you’d like to add to the collection.

Organize your collections by projects, add, remove, edit, and rename icons.

Use the «Paint collection» feature and change the color of the whole collection or do it icon by icon.

Download your collections in the code format compatible with all browsers, and use icons on your website.

Save a backup copy of your collections or share them with others- with just one click!

You have reached your collections limit. Upgrade to get unlimited collections

Register and create new collections

Are you sure you want to delete this collection?

We are sorry you canceled your Premium subscription

You can still enjoy Flaticon Collections with the following limits:

  • You can choose only 3 collections to keep
  • You can only add up to 100 icons per collection
  • You cannot add Premium icons to your collection
The advantages of your collections changed
  • You can choose only 3 collections to keep
  • You can only add up to 100 icons per collection
  • You cannot add Premium icons to your collection

Keep making the most of your icons and collections

Get 20% OFF our
Annual Premium Plan

Источник

Оцените статью