How to use SVG image in ImageView

Solution 1:

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"

Solution 2:

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"

Solution 3:

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.

Solution 4:

Though SVG is XML-based Vector image, Imageview can render only XML(Vector Drawables). Thus, We need to convert SVG to XML format. We can do it using Android Vector Asset Studio.

This may be helpful to convert SVG, PSD to XML
https://medium.com/@iamitgupta1994/converting-svg-psd-to-xml-vector-drawable-using-android-vector-asset-studio-8e8ec23d5405

Solution 5:

Right Click on Drawable -> New -> Vector Asset -> select Local file (SVG, PSD) select Path where your image

example /Users/yourpcname/Desktop/taka.svg

enter image description here

enter image description here

its save drawable as a xml file Then you can use into your imageview.