Support library VectorDrawable Resources$NotFoundException

前端 未结 14 1338
你的背包
你的背包 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:58

    Sorry for being late to the party but this answer may help users who want to enable the flag AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); for all activities.

    1. Create a class which extends to Application (android.app.Application)

    public class MyApplicationClass extends Application
    {
        @Override
        public void onCreate()
        {
            super.onCreate();
        }
    }
    

    2. Head over to Manifest.xml and add the following line to your tag

    
        ...
    
    

    3. Add the following code above onCreate in MyApplicationClass.java

    // This flag should be set to true to enable VectorDrawable support for API < 21
    static
    {
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    }
    

    Complete code for MyApplicationClass.java

    import android.app.Application;
    import android.support.v7.app.AppCompatDelegate;
    
    /**
    * Created by Gaurav Lonkar on 23-Dec-17.
    */
    
    public class MyApplicationClass extends Application
    {
        // This flag should be set to true to enable VectorDrawable support for API < 21
        static
        {
            AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
        }
    
        @Override
        public void onCreate()
        {
            super.onCreate();
        }
    }
    

提交回复
热议问题