Reputation: 1249
I have the cardview with rounded corners and imageview inside. I want to set background color :
cv.setBackgroundColor(Color.RED)
But the corners are not rounded in this case enter image description here
I tryed
cv.setCardBackgroundColor(Color.RED)
but in this case i can't see red color at all (with any margin and padding values)
Upvotes: 0
Views: 1014
Reputation: 193
You need to create a Drawable
and set it as the background for your CardView
.
Lets say this is a drawable named CardViewBackground
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/holo_dark_red"/>
<corners android:radius="10dp">
</shape>
</item>
</selector>
Then in my CardView
I can do
<CardView....
android:background="@drawable/CardViewBackground"
/>
Upvotes: 2