Without directly go for the solution first we need to clear the concept of what is vector drawables in android.
VectorDrawable is a vector graphic defined in an XML file as a set of points, lines, and curves along with its associated color information? The major advantage of using a vector drawable is image scalability. It can be scaled without loss of display quality, which means the same file is resized for different screen densities without loss of image quality. This results in smaller APK files and less developer maintenance. You can also use vector images for animation by using multiple XML files instead of multiple images for each display resolution.
Recently I was developing the application I used vector drawables throughout in my application I set the vector drawable to textview so what happened when I used vector drawables on pre-lollipop. Everything works fine but when I use.
On ImageView, ImageButton, TextView & EditText.
Exception on Pre-lollipop:
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/search_toggle.xml from drawable resource ID #0x7f0200a9
Doing a lot of R&D I got the answer, we need to set the drawable on textView, imageView, imageButton & EditText programmatically. I created a function which sets the vector drawable without any issue. You can see the code below:
How to use it:
Just call out the function and pass it the parameters like the below:
So that’s it…. now you can see there will be no crash on pre-lollipop. Happy Coding :-)
If you want to learn more related to Android then check it out the below link:
If you want to learn something about vector drawables then check it out the official link below.