Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent background on CardView - Android

I want to do transparent background on CardView. I know backgroundColor but i have image on my Layout.

Do you know how do it? Or something which work as cardview but i will set a transparent background?

Regards

like image 539
mac229 Avatar asked Feb 20 '15 12:02

mac229


People also ask

How do I customize my CardView?

Customized CardView First, add a CardView dependency to the application-level build. gradle file. Then create a drawable background for the cards. For that, create a new drawable resource file inside the drawable folder.

How do you change the background on an Android card?

To set the background color of a card, use the card_view:cardBackgroundColor attribute.


1 Answers

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); 
like image 149
Chris Stillwell Avatar answered Sep 29 '22 05:09

Chris Stillwell