踩坑实录 使用 cardview 时报错 error: No resource identifier found for attribute 'cardCornerRadius' in package 'com.xxxxx.xxx'

时间:2022-06-25 11:59:50

在项目中引用 cardview 卡片布局,编译时 Android Studio 报出下面图片中红框标记的错误:

踩坑实录  使用 cardview 时报错   error: No resource identifier found for attribute 'cardCornerRadius' in package 'com.xxxxx.xxx'

出现这种情况的原因在于没有导入 cardview 卡片布局相应的依赖包,因此我们需要在 build.gradle 文件中添加相应的依赖,

compile 'com.android.support:cardview-v7:25.3.0'

需要注意的是,cardview 的依赖版本不能高于 support:appcompat 的版本数,否则无法成功添加依赖!
我的 support:appcompat 版本为 compile 'com.android.support:appcompat-v7:25.3.0' ,因此cardview 的版本必须小于等于此版本方可成功添加依赖。