[英]How to set semi transparent background color for Android CardView?
I want to set the backgroundColor of a card view with an argb color.我想用 argb 颜色设置卡片视图的背景颜色。 But the result is like this:但结果是这样的:
<androidx.cardview.widget.CardView
android:id="@+id/infoCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
app:cardBackgroundColor="#59448AFF"
app:cardCornerRadius="8dp">
<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/space_16dp"
android:layout_marginTop="@dimen/space_8dp"
android:layout_marginEnd="@dimen/space_16dp"
android:layout_marginBottom="@dimen/space_8dp"
android:lineSpacingExtra="@dimen/space_4dp"
android:text="This is a sample text"
android:textColor="@color/secondaryText"
android:textSize="16sp" />
</androidx.cardview.widget.CardView>
Does anybody know how to fix this?有人知道如何解决这个问题吗?
Define it within color.xml
在color.xml
中定义它
<color name="semiTransparentColor">#20ffffff</color>
Now set the card view like this way.现在像这样设置卡片视图。
card_view:cardBackgroundColor="@color/semiTransparentColor"
Here is the code of hexadecimal code of transparency.这里是透明度的十六进制代码。 link you can set as you need.您可以根据需要设置链接。
Just set this to a card view只需将其设置为卡片视图
app:cardElevation="0dp"
or try with removing the background of your com.google.android.material.textview.MaterialTextView或尝试删除 com.google.android.material.textview.MaterialTextView 的背景
android:background="@null"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.