Set android:backgroundTint="@android:color/transparent" . This is CardView attribute to set background. Set android:cardElevation="0dp" to remove the shadow.
You need to use a drawable background ( shadow. xml ) in the parent layout which is looking like a shadow. You can replace FF46A9 in shadow. xml to change the color of shadow.
You can actually apply a hex code color that is transparent. The hex code for transparent white (not that the color matters when it is fully transparent) is two zeros followed by white's hex code of FFFFFF or 00FFFFFF.
If you want to change the card background color, use:
app:cardBackgroundColor="@somecolor"
like this:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/white">
</android.support.v7.widget.CardView>
Edit: As pointed by @imposible, you need to include
xmlns:app="http://schemas.android.com/apk/res-auto"
in your root XML tag in order to make this snippet function
You can do it either in XML or programmatically:
In XML:
card_view:cardBackgroundColor="@android:color/red"
Programmatically:
cardView.setBackgroundColor(ContextCompat.getColor(this, R.color.my_color));
Kotlin for XML
app:cardBackgroundColor="@android:color/red"
code
cardName.setCardBackgroundColor(ContextCompat.getColor(this, R.color.colorGray));
XML code
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="5dp"
app:contentPadding="25dp"
app:cardBackgroundColor="#e4bfef"
app:cardElevation="4dp"
app:cardMaxElevation="6dp" />
From the code
CardView card = findViewById(R.id.card_view_top);
card.setCardBackgroundColor(Color.parseColor("#E6E6E6"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With