I want to set some vectorDrawables to a ImageView in Android Studio.
I can set png and jpg drawable easily but when i want to set VectorDrawable, it does not work on imageview.
img.setImageResource(R.drawable.ic_home);
ic_home is VectorDrawable and this code doesn't work.
I had a vector in recycler view I was using
img.setImageResource(R.drawable.ic_home)
which didn't worked properly like some other image get formed in some item of recycler view. Then I usedimg.setImageDrawable(activity.getResources().getDrawable(R.drawable.ic_home))
this worked .if you are concerned with the backward compatibility then you should use
AppCompatImageView
instead of image view. go through the code below.java
below code need to add in build.gradle
android { defaultConfig{ vectorDrawables.useSupportLibrary = true } }
And it will serve the perspective of app:srcCompat.