我想在CardView上做透明背景。我知道backgroundColor但我的布局上有图像。
你知道怎么做吗?或作为cardview起作用的东西,但我将设置透明背景?
问候
我想在CardView上做透明背景。我知道backgroundColor但我的布局上有图像。
你知道怎么做吗?或作为cardview起作用的东西,但我将设置透明背景?
问候
Answers:
设置CardView以使用该cardBackgroundColor属性删除颜色,并使用该属性删除cardElevation阴影。例如:
<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/myCardView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    card_view:cardBackgroundColor="@android:color/transparent"
    card_view:cardElevation="0dp"> 
有关受支持属性的完整列表,请参见此处:https : //developer.android.com/reference/android/support/v7/widget/CardView.html
如果您使用的是较旧的API,则需要在您的API上调用以下两个函数CardView:
myCardView.setCardBackgroundColor(Color.TRANSPARENT);
myCardView.setCardElevation(0);
setCardElevation()然后setCardBackgroundColor()从您的代码上CardView看到我的编辑。
                    @null但是没有用,知道吗?
                    简单的2个步骤即可使AndroidCardView透明。
设置app:cardBackgroundColor="@android:color/transparent"。这是CardView设置背景的属性。
设置app:cardElevation="0dp"以去除阴影。
例如,下面是创建透明的小xml代码 CardView
<android.support.v7.widget.CardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:cardBackgroundColor="@android:color/transparent"
        app:cardElevation="0dp" />
注意:请勿使用
。使用setBackgroundapp:cardBackgroundColor代替。
就我而言,我使用的属性  android:backgroundTint="@color/some_color"仅在API级别21和更高版本中使用。而color #50000000例如。
<android.support.v7.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        card_view:cardCornerRadius="3dp"
        app:cardElevation="0dp"
        android:backgroundTint="@color/negro_label"
        >
这应该适用于API 17
cardView.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
使用     app:cardBackgroundColor="@android:color/transparent"
<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="20dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginTop="10dp"
    app:cardCornerRadius="16dp"
    app:cardElevation="16dp"
    app:cardBackgroundColor="@android:color/transparent" >
<--inside cardlayout-->
    </android.support.v7.widget.CardView>
android:background="@android:color/transparent"