How to use SVG image in ImageView How to use SVG image in ImageView android android

How to use SVG image in ImageView


In new Android Studio there is possibility to import SVG to XML file, so You don't need to use external library.

In drawable right click -> New -> Vector Asset -> Local SVG file.

enter image description here

Then You use it normally as other drawables:

android:src="@drawable/btn_image"


On newer devices that have hardware rendering turned on by default, you need to explicitly turn on software rendering.

imgView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

OR add this tag in your xml

android:layerType="software"


To properly use the svgimageview:svg attribute, the app needs to know it's definition. Unfortunately, there is only a JAR version of the library at the moment, and (unlike with AARs) the needed definition does not get merged properly when the app is built.

Try copying the attrs.xml file from the library source

https://github.com/BigBadaboom/androidsvg/blob/master/androidsvg/src/main/res/values/attrs.xml

into your res/values folder.

I believe that should fix your problem.