drawable/information.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M13,9H11V7H13M13,17H11V11H13M12,2A10,10 0,0 0,2 12A10,10 0,0 0,12 22A10,10 0,0 0,22 12A10,10 0,0 0,12 2Z"/>
</vector>
LayoutofCardView.xml
<ImageView
android:layout_width="24dp"
android:background="#f00"
android:layout_height="24dp"
android:id="@+id/informationImageView"
app:srcCompat="@drawable/information"
tools:src="@drawable/information"
/>
构建.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.company"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:cardview-v7:23.2.1'
compile 'com.android.support:recyclerview-v7:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
}
图像在 android studio 的设计面板中正确显示。但是当我运行应用程序时,图像没有显示。图片在cardView中,cardView在recyclerviewfragment中。其他项目正确呈现只有矢量 drawbles 不呈现。
此外,Lint 错误出现在布局文件中
unexpected namespace prefix "app" found for tag ImageView app:srcCompat
最佳答案
将此行 vectorDrawables.useSupportLibrary = true 作为 defaultConfig 语句的一部分插入到您的 build.graddle 文件中。我使用了提供的描述 here它有效。认为您必须意识到 Gradle 2.0+ 和 Gradle 1.5 的配置看起来不同。
无论您使用的是哪个 Gradle 版本,您都必须确保您的 Activity 必须扩展 AppCompatActivity提供载体支持。
关于android - 应用程序 :srcCompat - Vector drawable shows up in design preview, 但未显示在应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36220868/