Updated 24 September 2023
Then, the answer is yes.
Vector drawables allow us to replace multiple png assets with a single vector graphic, defined in XML. While previously limited to Lollipop and higher devices.
Which means:
No Multiple PNG’s based on densities.
Application Size reduction: Less Assets less memory consumption.
SVG are lighter than multiple PNG’s used in an application. They are even lighter than a single PNGs.
For v2.0 or above of the Gradle plugin: we have to add the following in the module level gradle.build
1 2 3 4 5 |
android { defaultConfig { vectorDrawables.useSupportLibrary = true } } |
However to technical bug described below:
First up, this functionality was originally released in 23.2.0, but then we found some memory usage and Configuration updating issues so we it removed in 23.3.0. In 23.4.0 (technically a fix release) we’ve re-added the same functionality but behind a flag which you need to manually enable. – ANDROID TEAM
So in order to enable the configuration, we need to add the following in each activity where we are using Vector images or in the Application class of the project.
1 |
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); |
We can convert the SVG image into <vector> using Asset Studio.
Here are the steps for converting SVG into Vector Drawable Compat.
We can also use online open source tools for conversion:
http://inloop.github.io/svg2android/
For setting Vector Image:
1 2 3 4 |
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_wishlist_checked"/> |
The line android:src=”@drawable/ic_wishlist_checked” will give the warning as we need to use
1 |
app:srcCompat="@drawable/ic_wishlist_checked" |
For changing programmatically:
1 |
imageView.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_wishilist_checked)); |
instead of
1 |
imageView.setImageResource(R.drawable.drawable_image); |
So guys
STAY UPDATED !! HAPPY CODING !!
References:
https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.rrpqvg79e
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.