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>

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


目录
打赏
0
0
0
0
10
分享
相关文章
Android系统 init.rc sys/class系统节点写不进解决方案和原理分析
Android系统 init.rc sys/class系统节点写不进解决方案和原理分析
632 0
Curl error (60): SSL peer certificate or SSH remote key was not OK for https://update.cs2c.com.cn/NS/V10/V10SP2/os/adv/lic/base/x86_64/repodata/repomd.xml [SSL: no alternative certificate subject name matches target host name 'update.cs2c.com.cn']
【10月更文挑战第30天】在尝试从麒麟软件仓库(ks10-adv-os)下载元数据时,遇到 SSL 证书验证问题。错误提示为:`Curl error (60): SSL peer certificate or SSH remote key was not OK`。可能原因包括证书不被信任、证书与域名不匹配或网络问题。解决方法包括检查网络连接、导入 SSL 证书、禁用 SSL 证书验证(不推荐)、联系仓库管理员、检查系统时间和尝试其他镜像。
1391 1
解决Android运行出现NDK at /Library/Android/sdk/ndk-bundle did not have a source.properties file
解决Android运行出现NDK at /Library/Android/sdk/ndk-bundle did not have a source.properties file
308 4
解决Android运行出现NDK at /Library/Android/sdk/ndk-bundle did not have a source.properties file
解決Android报错:Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
解決Android报错:Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
246 1
问题:Android requires .class compatibility set to 5.
问题:Android requires .class compatibility set to 5.
56 1
How to decompile Google Android .apk file as readable dump【原创】
How to decompile Google Android .apk file as readable dump【原创】
62 0
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
113 0
讲解SSM的xml文件
本文详细介绍了SSM框架中的xml配置文件,包括springMVC.xml和applicationContext.xml,涉及组件扫描、数据源配置、事务管理、MyBatis集成以及Spring MVC的视图解析器配置。
145 1

热门文章

最新文章