【问题标题】:Cardview with rounded corners background color带有圆角背景颜色的 Cardview
【发布时间】:2018-12-14 22:27:47
【问题描述】:

我有圆角的卡片视图和里面的图像视图。我想设置背景颜色:

cv.setBackgroundColor(Color.RED)

但在这种情况下,边角不是圆角的 enter image description here

我试过了

cv.setCardBackgroundColor(Color.RED)

但在这种情况下,我根本看不到红色(带有任何边距和填充值)

【问题讨论】:

  • 请发布您的xml文件

标签: android cardview


【解决方案1】:

您需要创建一个Drawable 并将其设置为您的CardView 的背景。

假设这是一个名为CardViewBackground的drawable

<?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>

然后在我的CardView 我可以做到

<CardView....
    android:background="@drawable/CardViewBackground"
/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-23
    • 2023-03-19
    • 2018-08-19
    • 2013-04-28
    • 1970-01-01
    • 2019-05-17
    相关资源
    最近更新 更多