I am attempting to use vector drawables in my Android app. From http://developer.android.com/training/material/drawables.html (emphasis mine):
In And
First : import svg to drawble : ((https://www.learn2crack.com/2016/02/android-studio-svg.html))
1-Right click on the drawable folder select New -> Vector Asset
2- The Vector Asset Studio provides you option to select the inbuilt Material icons or your own local svg file. You can override the default size if needed.
Second :if you want support from android API 7+ , you have to use Android Support Library acording ((https://stackoverflow.com/a/44713221/1140304))
1- add
vectorDrawables.useSupportLibrary = true
to your build.gradle file.
2-Use namespace in your layout that has imageView :
xmlns:app="http://schemas.android.com/apk/res-auto"
Third : set imageView with android:scaleType="fitXY" and use app:srcCompat
Fourth :if you want set svg in java code you have to add below line on oncreate methoed
@Override
protected void onCreate(Bundle savedInstanceState)
{
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}