Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VectorDrawable - is it available somehow for pre-Lollipop versions of Android? [closed]

Background

I've noticed that Android now supports some kind of vector drawing, via a class called "VectorDrawable" (and also AnimatedVectorDrawable, BTW). I've found about it by looking at what's new on Android-Studio.

I wonder if this would be the end of having to put multiple files into multiple folders (mdpi, hdpi, xhdpi, etc). That would be great and might minimize apps sizes on some cases.

The questions

I'd like to ask a few questions regarding this new class:

  1. Is it possible to use it in older Android versions, maybe via a library of even the support library of Google?

  2. I'm not familiar with how it works, but can Lollipop handle SVG files? Can it do anything that is achievable on SVG files?

  3. Is there any sample/tutorial/video of using it, other than the documentation I've found?

like image 392
android developer Avatar asked Oct 24 '14 12:10

android developer


3 Answers

UPDATE ON March 2016

By Android Support Library 23.2.1 update, Support Vector Drawables and Animated Vector Drawables. (you can also use latestone for the same)

Please update version of a library in gradle file.

compile 'com.android.support:recyclerview-v7:23.2.1'

Vector drawables allow you to replace multiple png assets with a single vector graphic, defined in XML. While previously limited to Lollipop and higher devices, both VectorDrawable and AnimatedVectorDrawable are now available through two new Support Libraries support-vector-drawable and animated-vector-drawable. new app:srcCompat attribute to reference vector drawables .

Check source on github with some sample examples.

Changes for v7 appcompat library:

Reverted dependency on vector assets so that developers using the appcompat library are not forced to use VectorDrawable and its associated build flags.

like image 149
Amit Vaghela Avatar answered Oct 21 '22 07:10

Amit Vaghela


Update 2: They enable it again in Support Library 23.4.0:

For AppCompat users, we’ve added an opt-in API to re-enable support Vector Drawables from resources (the behavior found in 23.2) via AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) - keep in mind that this still can cause issues with memory usage and problems updating Configuration instances, hence why it is disabled by default.

Check this 23.4.0 available now

Update: This doesn't work from version 23.3.0 Check here for details. Proxy drawables don't work. app:srcCompat and setImageResource() work, however.


Vector Drawable support is available from the Support Library of version 23.2 and beyond. However, to properly use those drawables, they must be referenced indirectly.

First step would be to bump the AppCompat version.

compile 'com.android.support:appcompat-v7:23.2.0'

Second enable Vector Drawable support. If using Gradle plugin, 2.0+

android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
   }  
}

Otherwise

android {  
   defaultConfig {  
     generatedDensities = []  
   }  

   aaptOptions {  
     additionalParameters "--no-version-vectors"  
   }  
}

Third, refer to the linked answer.

like image 14
razzledazzle Avatar answered Oct 21 '22 05:10

razzledazzle


You can try this support library. It supports VectorDrawable and AnimatedVectorDrawable introduced in Lollipop with fully backwards compatibility.

like image 12
V_J Avatar answered Oct 21 '22 06:10

V_J