Support library VectorDrawable Resources$NotFoundException

前端 未结 14 1377
你的背包
你的背包 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 18:55

    In my particular case, I had this problem because I was using a drawable selector as the image resource with several vectors in the selector, as in:

    
        
        
        .
        .
        etc
    
    

    Yes, pretty bad, but didn't know better at the time.

    So, the right way of doing this is using the tint property in your vector file, as in:

    
                  
    
    

    (You can also use the app:tint attribute in the AppCompatImageView)

    And now, your vector_color_selector file should have the colors you want, as in:

    
        
        
        .
        .
        etc
    
    

    I hope this helps someone if previous answers didn't work for you. Stating the obvious, but I must say that you still need to set vectorDrawables.useSupportLibrary = true in gradle, use AppCompatImageView and use app:srcCompat or setImageDrawable + AppCompatResources.getDrawable to avoid any troubles with the vector compat library.

提交回复
热议问题