Android 使用矢量绘图兼容程序
我正在用一些片段制作一个android应用程序。在其中一个片段中,我有一个带有返回箭头作为图像按钮的工具栏。Android 使用矢量绘图兼容程序,android,android-vectordrawable,Android,Android Vectordrawable,我正在用一些片段制作一个android应用程序。在其中一个片段中,我有一个带有返回箭头作为图像按钮的工具栏。 在XML文件中,我有“app:srcCompat”属性,但在使用该属性时出现错误:“要使用VectorDrawableCompat,需要设置'android.defaultConfig.vectorDrawables.useSupportLibrary=true' 添加到图像按钮: tools:ignore="VectorDrawableCompat" 在模块build.gradle
在XML文件中,我有“app:srcCompat”属性,但在使用该属性时出现错误:“要使用VectorDrawableCompat,需要设置'android.defaultConfig.vectorDrawables.useSupportLibrary=true'
添加到图像按钮:
tools:ignore="VectorDrawableCompat"
在模块
build.gradle
文件中,需要添加以下行:
apply plugin: 'com.android.application'
android {
...
defaultConfig {
...
vectorDrawables.useSupportLibrary = true // This line here
}
...
}
...
将此行添加到
defaultConfig
block下的Gradle文件中:
vectorDrawables.useSupportLibrary = true
此外,您需要在每个活动或片段中添加此代码块,在这些活动或片段中,您引用的是drawables,而不是srcCompat
中的图像:
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
您可以使用以下行
android:src="@drawable/edit"
您必须在应用程序级别build.gradle的
defaultConfig
标记中添加vectorDrawables.useSupportLibrary=true
这一行代码
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"
}
嗯……它已经告诉你解决方案了!
要使用VectorDrawableCompat,你需要设置“android.defaultConfig.vectorDrawables.useSupportLibrary=true”
我也有同样的问题,我没有做建议的解决方案,但所有东西都可以在新旧设备上运行。我想知道,如果这些警告似乎没有影响,为什么会不断出现什么都没有。@ModularSynth对于新手来说,它不清楚应该添加到哪里,更不用说如何添加了。如果它已经添加了,但仍然收到“错误/警告”@muhammedreat尝试重新同步您的项目识别问题不是一个解决方案