我正在制作一个带有几个片段的Android应用程序。在其中一个片段中,我有一个带有后箭头的工具栏作为图像按钮。 在XML文件中,我有“app:srcCompat”属性,但是在使用这个属性时我得到一个错误:“要使用VectorDrawableCompat,你需要设置'android.defaultConfig.vectorDrawables.useSupportLibrary = true'
在您的模块build.gradle
文件中,您需要添加以下行:
apply plugin: 'com.android.application'
android {
...
defaultConfig {
...
vectorDrawables.useSupportLibrary = true // This line here
}
...
}
...
将此行添加到defaultConfig
块下的Gradle文件中:
vectorDrawables.useSupportLibrary = true
此外,您需要在您引用drawables而不是srcCompat
中的图像的每个活动或片段中添加此代码块:
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
您可以使用以下行
android:src="@drawable/edit"
添加到您的ImageButton:
tools:ignore="VectorDrawableCompat"