使用Vector Drawable Compat

时间:2016-12-19 15:51:15

标签: android android-vectordrawable

我正在制作一个带有几个片段的Android应用程序。在其中一个片段中,我有一个带有后箭头的工具栏作为图像按钮 在XML文件中,我有" app:srcCompat"属性,但在使用此属性时出现错误:"要使用VectorDrawableCompat,您需要设置' android.defaultConfig.vectorDrawables.useSupportLibrary = true'

5 个答案:

答案 0 :(得分:56)

在您的模块build.gradle文件中,您需要添加以下行:

apply plugin: 'com.android.application'

android {
    ...

    defaultConfig {
        ...

        vectorDrawables.useSupportLibrary = true // This line here
    }
    ...
}

...

答案 1 :(得分:7)

将此行添加到var hours = 3; var minutes = 25; var seconds = 58; var amount = 100; var result = hours*amount + minutes*amount/60 + seconds*amount/3600; 块下的Gradle文件中:

defaultConfig

此外,您需要在您引用drawables而不是vectorDrawables.useSupportLibrary = true 中的图片的每个活动或片段中添加此代码块:

srcCompat

答案 2 :(得分:2)

您必须在vectorDrawables.useSupportLibrary = true标签内的应用级别build.gradle中添加defaultConfig这行代码

defaultConfig {
        applicationId "your package Name"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "0.0.1"
        //This is the Main Line you have to add to avoid this warning.
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

答案 3 :(得分:0)

您可以使用以下行

android:src="@drawable/edit"

答案 4 :(得分:-6)

添加到您的ImageButton:

tools:ignore="VectorDrawableCompat" 
相关问题