在布局文件中使用app命名空间时,需要在根元素中声明app命名空间,否则会出现该错误。
例如,在使用cardView组件时,需要在根元素添加如下声明:
xmlns:app="http://schemas.android.com/apk/res-auto"
完整示例代码:
android:layout_width="match_parent"
android:layout_height="match_parent">
app:cardElevation="2dp">