Support library VectorDrawable Resources$NotFoundException

前端 未结 14 1292
你的背包
你的背包 2020-11-29 18:40

I am using Design Support Library version 23.4.0. I have enabled the gradle flag:

defaultConfig {
    vectorDrawables.useSupportLibrary = tr         


        
相关标签:
14条回答
  • 2020-11-29 19:05

    It took 3 separate things for me to get this to work using support library 23.4.0:

    1. Add this to build.gradle

      defaultConfig {
          vectorDrawables.useSupportLibrary = true
      }
      
    2. Add the following to onCreate of your Application class

      AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
      

      (From the reference of this link - "https://stackoverflow.com/a/45582033/10752962")

      In API less then 21,use this line before setContentView();

    3. For all XML views in which you are setting a vector drawable replace

      android:src
      

      with

      app:srcCompat
      

      and in the code replace this:

      imageView.setImageResource(...);
      

      with

      imageView.setImageDrawable(...);
      
    0 讨论(0)
  • 2020-11-29 19:05

    Support for vector drawables in places like android:drawableLeft was disabled in support library 23.3. It was announced on Google+:

    we’ve decided to remove the functionality which let you use vector drawables from resources on pre-Lollipop devices due to issues found in the implementation in version 23.2.0/23.2.1. Using app:srcCompat and setImageResource() continues to work.

    Links to issues:

    • https://code.google.com/p/android/issues/detail?id=205236
    • https://code.google.com/p/android/issues/detail?id=204708

    However, if you can live with those issues, in 23.4 you can re-enable this functionality using AppCompatDelegate.setCompatVectorFromResourcesEnabled().

    If you're curious how this works, the best person to learn from is Chris Banes, who authored this functionality. He explains in detail on his blog.

    0 讨论(0)
提交回复
热议问题