Is that right to make android.view.InflateException by using Vector drawables in android:background: line in a ImageView

前端 未结 2 1085
渐次进展
渐次进展 2021-01-28 03:59

I am facing android.view.InflateException in my app for some particular devices, in others phone it works fine. But i don\'t know why. Many others says that this pr

相关标签:
2条回答
  • 2021-01-28 04:12

    Use color code replace of color name from color.xml in your drawable vector xml like below;

    <vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#4396e6"
        android:pathData="M21,19V5c0,-1.1 -0.9,-2 -2,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2zM8.5,13.5l2.5,3.01L14.5,12l4.5,6H5l3.5,-4.5z"/>
    

    0 讨论(0)
  • 2021-01-28 04:24

    Make sure you have added vectorDrawables.useSupportLibrary = true inside defaultConfig in app/build.gradle.

    Like

    defaultConfig {
            vectorDrawables.useSupportLibrary = true
            ....
     }
    

    EDIT 1 In order to support vector in API less then 21. Also add this in onCreate method of Activity before setContentView.

    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    
    0 讨论(0)
提交回复
热议问题