Android Binary XML file line #50: Error inflating class androidx.cardview.widget.CardView 错误

简介: Android Binary XML file line #50: Error inflating class androidx.cardview.widget.CardView 错误

前言:

今天在使用卡片视图CardView,启动APP后出现程序停止运行,报错如下:

Binary XML file line #50: Error inflating class androidx.cardview.widget.CardView

报错显示在xml布局第50行

<androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_marginTop="35dp"
                android:layout_marginRight="15dp"
                android:layout_marginBottom="15dp"
                app:cardCornerRadius="4dp"
                >
                <TextView
                    android:id="@+id/tv_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:text="我这里是一个卡片布局!" />
            </androidx.cardview.widget.CardView>

解决方案:

必须要设置卡片的背景颜色,属性为:app:cardBackgroundColor="@color/white"

<androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_marginTop="35dp"
                android:layout_marginRight="15dp"
                android:layout_marginBottom="15dp"
                app:cardCornerRadius="4dp"
                app:cardBackgroundColor="@color/white"
                >
                <TextView
                    android:id="@+id/tv_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:text="我这里是一个卡片布局!" />
            </androidx.cardview.widget.CardView>

这样设置之后重新运行程序就可以了。


目录
相关文章
|
19天前
|
开发工具 Android开发 git
解决Android AAPT: error: resource android:attr/lStar not found. 问题
解决Android AAPT: error: resource android:attr/lStar not found. 问题
91 0
|
19天前
|
开发工具 Android开发 Windows
Android应用] 问题2:ERROR: unknown virtual device name:
Android应用] 问题2:ERROR: unknown virtual device name:
13 2
|
19天前
|
openCL 开发工具 异构计算
mtk make:*** [xml_parser] Error 255
mtk make:*** [xml_parser] Error 255
12 0
|
19天前
|
Android开发 开发者
安卓投屏神器 Scrcpy安 报错ERROR: Could not find any ADB device
使用Scrcpy安卓投屏工具时遇到报错,问题根源是未开启开发者模式。解决步骤:进入设置,点击【关于手机】→连续点击版本号激活开发者模式,然后在【系统设置】→【开发者选项】中开启USB调试。参照此方法后可正常执行。Scrcpy软件下载链接和GitHub页面也已提供。
64 1
|
19天前
|
XML Android开发 数据格式
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class
24 0
|
19天前
|
XML 数据格式
小米备份descript.xml文件
小米备份descript.xml文件
37 0
|
19天前
|
XML Java 数据库连接
mybatis中在xml文件中通用查询结果列如何使用
mybatis中在xml文件中通用查询结果列如何使用
51 0
|
19天前
|
XML JavaScript 前端开发
xml文件使用及解析
xml文件使用及解析
|
19天前
|
SQL
Mybatis.xml文件中大于小于等于
Mybatis.xml文件中大于小于等于
14 0
|
19天前
|
XML 关系型数据库 MySQL
【Mysql】有关数据库中一对多/一对一,多对一xml中文件映射问题
【Mysql】有关数据库中一对多/一对一,多对一xml中文件映射问题
23 0