为什么 CardView 背景颜色会改变?

时间:2021-04-12 18:25:33

标签: java android xml

我创建了一个背景颜色为红色的 CardView。在新设备上,它显示一个红色圆圈,但在旧设备(例如我的虚拟设备)上,它显示一个带有阴影的透明圆圈。

现在我很好奇圆圈在某些设备上是如何透明的,而在某些设备上不是透明的?

这是activity_main.xml的cardView部分

<androidx.cardview.widget.CardView
                    android:id="@+id/notification_circle"
                    android:layout_width="10dp"
                    android:layout_height="10dp"
                    app:cardBackgroundColor="@color/red"
                    app:cardCornerRadius="50dp"
                    app:layout_constraintEnd_toEndOf="@+id/notiButton"
                    app:layout_constraintTop_toTopOf="@+id/notiButton">


                    <androidx.constraintlayout.widget.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">

                        <TextView
                            android:id="@+id/notification_number"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text=""
                            android:textColor="@color/white"
                            android:textStyle="bold"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent" />


                    </androidx.constraintlayout.widget.ConstraintLayout>

结果应该是这样的: Should be

但这是实际结果: The actual result

提前致谢!

0 个答案:

没有答案