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>

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

你可能感兴趣的:(Android,bug解决方案,android,xml,bug,CardView,卡片视图)