Can't use srcCompat for ImageViews in android

前端 未结 12 537
借酒劲吻你
借酒劲吻你 2020-12-03 00:38

I\'m using the Design Support Library 23.2. I\'ve added these lines in my build.gradle as my Gradle Plugin is version 1.5

defaultConfig {
        applicat         


        
12条回答
  •  被撕碎了的回忆
    2020-12-03 01:19

    there is multiple things which you have to care about First of all use:

    defaultConfig {
                vectorDrawables.useSupportLibrary = true
            }
    

    or

    vectorDrawables {
            useSupportLibrary = true
        }
    

    and Secondly use

     
    

    Always use AppCompatImageView or Button because vector image is not supported by Simple ImageView

    if all the above methods not worked then use

    public class App extends Application {
    
      @Override public void onCreate() {
        super.onCreate();
    
        // Make sure we use vector drawables
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
      }
    }
    

    If you are using Activity then extend your Activity with AppCompatActivty

    public final class MainActivity extends AppCompatActivity {    
      @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.activity_main);
      }
    }
    

提交回复
热议问题