简体   繁体   English

你如何使Recyclerview和Cardview透明

[英]How do you make the Recyclerview and Cardview transparent

I have a recyclerview that I would like to share the same background as the activity so that only the textviews inside the recyclerview are visible.我有一个 recyclerview,我想与活动共享相同的背景,以便只有 recyclerview 内的文本视图可见。 I've tried things like this in the cardview and recyclerview xmls:我在 cardview 和 recyclerview xmls 中尝试过这样的事情:

android:background="@android:color/transparent"

and

android:background="@null"

They haven't worked.他们没有工作。 Is this possible?这可能吗? I haven't found any answers in previously asked questions on here that have been successful.我还没有在之前在这里提出的问题中找到任何成功的答案。 Any ideas appreciated!任何想法表示赞赏!

Cardview is for beautifying layout and giving shadow to it, If you don't want to use this feature than you should avoid CardView and use simple LinearLayout , RelativeLayout , ConstraintLayout etc. and than give transparent background to it. Cardview 用于美化布局并为其添加阴影,如果您不想使用此功能,则应避免使用 CardView 并使用简单的LinearLayoutRelativeLayoutConstraintLayout等,而不是为其提供透明背景。

But still you want to use CardView, remove this line但是你仍然想使用 CardView,删除这一行

android:background="@android:color/transparent"

and add this line to your CardView.并将此行添加到您的 CardView。

 app:cardBackgroundColor="@android:color/transparent"

If you are using fragment, you need to add it on your container instead of replacing it:如果您正在使用片段,则需要将其添加到您的容器中而不是替换它:

supportFragmentManager.beginTransaction().add(YourFragment(),"tag").commit()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM