Transparent background on CardView - Android
In my case, I used the attribute android:backgroundTint="@color/some_color"
,it is only used en API level 21 and higher. And color #50000000
for example.
<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"
>
in SDK version 21 or higher steps to make Android CardView
transparent.
Set
android:backgroundTint="@android:color/transparent"
. This isCardView
attribute to set background.Set
android:cardElevation="0dp"
to remove the shadow.
For example, here is small xml code to create transparent CardView
<androidx.cardview.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" />
Setup your CardView to use the cardBackgroundColor
attribute to remove color and cardElevation
attribute to remove the drop shadow. For example:
<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">
For a full list of supported attributes see here: https://developer.android.com/reference/android/support/v7/widget/CardView.html
If you are using an older API, you will need to call these two functions on your CardView
instead:
myCardView.setCardBackgroundColor(Color.TRANSPARENT);
myCardView.setCardElevation(0);