所以我觉得我错过了一些东西,但我就是想不通。所以我想在我的CardView的顶部做一个小的色带,但是如果我使用框架布局,或者任何一种布局并设置背景颜色,它会覆盖CardView的圆角。以下是该问题的一些代码和屏幕截图。提前谢谢你!
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
card_view:cardCornerRadius="10dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="16dp"
android:layout_gravity="end"
android:background="@color/colorPrimaryDark"
android:clipChildren="true"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/menuCardImage"
android:layout_width="128dp"
android:layout_height="128dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_margin="8dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_margin="8dp"
android:layout_toRightOf="@+id/menuCardImage"
android:orientation="vertical">
<TextView
android:id="@+id/menuCardName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="32sp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>

编辑:原来这只是android studio的显示问题。当我安装应用程序时,它工作正常。
发布于 2017-06-05 16:37:05
不是将颜色设置为背景,而是使用此可绘制设置背景。
在drawable文件夹中创建top_strip.xml。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
<solid android:color="#FFffffff"/>
</shape>将半径设置为卡片边角半径,并根据需要更改颜色。看起来不错
发布于 2018-08-31 00:20:38
您现在可以设置CardView颜色。
color = ContextCompat.getColor(cardView.getContext(), R.color.white);
cardView.setCardBackgroundColor(color);这是最简单的方法。
发布于 2019-05-17 10:33:06
我认为你应该尝试使用app:cardBackgroudColor和CardView.setCardBackgroundColor。这对我很有帮助。
https://stackoverflow.com/questions/44362879
复制相似问题