Drawable as Background for CardView

匿名 (未验证) 提交于 2019-12-03 01:49:02

问题:

the CardView ( android.support.v7.cardview ) stays white even though I set a backround drawable via android:backround - The documentation gives me the feeling that it should work. No Idea what I am doing wrong here.

回答1:

I know this is an old question, but I have a simple solution - just make the first child of your CardView an ImageView and specify the scale type to fitXY. You can get rid of the extra CardView padding by setting cardElevation and cardMaxElevation to 0dp:

<... your="" layout="" ...="">


回答2:

Make Cardview will host one viewgroup for eg relative layout in this case and then simply set any background to relative layout.



回答3:

for drawable or color just use:

cvSellerShopp.setBackgroundResource(R.drawable.ic_action_add_image); 

for color use:

 cvSellerShopp.setCardBackgroundColor(R.color.colorPrimary); 

but this one does not produce the intended results



回答4:

Try this

card_view:cardBackgroundColor="@android:color/holo_green_dark

here you can set any color or make it transparent by giving color transparent and if u wand some drawable like image or svg put RelativeLayout background



回答5:

You can use LinearLayout or Relative layout inside CardView and set drawable background it like below :

Below is my Drawable resource file :



回答6:

Use cardview:cardBackgroundColor attribute:

android.support.v7.cardview:cardBackgroundColor="@color/black" 

or in code,

myCardViewObject.setCardBackgroundColor(someIntColor) 

more info here: https://developer.android.com/reference/android/support/v7/widget/CardView.html



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!