android cardview透明,android – Cardview角落背景不透明

我有一个CardView支持小部件的自定义实现,但是当我将它包含在我的布局文件中时,我似乎无法获得角落的背景透明.但是,如果我只是将CardView支持小部件放在我的布局文件中,它就会突然运行.如何让自定义组件的角落透明?

4SLAf.png

这是我自定义CardView实现的布局文件:

view_card.xml

android:id="@+id/view_card"

android:layout_width="match_parent"

android:layout_height="wrap_content"

style="@style/Custom.Widget.CardView">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:padding="@dimen/default_padding">

android:id="@+id/view_mainText"

style="@style/Custom.Widget.TextView.Header"

android:textColor="@color/instruction_balloon_text"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

android:id="@+id/view_subText"

android:textSize="@dimen/text_size_medium"

android:textColor="@color/instruction_balloon_text"

android:singleLine="false"

android:text="Please remove white corners :-("

android:textIsSelectable="true"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

styles.xml

@color/card_backgroundColor

12dp

这是我的布局文件,包括两个CardViews.第一个带有白色角落,第二个带有与view_card.xml基本相同的布局但没有白色角落(透明).

的example.xml

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical">

android:id="@+id/custom_card_view"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="@dimen/default_margin" />

android:id="@+id/view_card"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="@dimen/default_margin"

style="@style/Custom.Widget.CardView">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:padding="@dimen/default_padding">

android:id="@+id/view_mainText"

style="@style/Custom.Widget.TextView.Header"

android:textColor="@color/instruction_balloon_text"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

android:id="@+id/view_subText"

android:textSize="@dimen/text_size_medium"

android:textColor="@color/instruction_balloon_text"

android:singleLine="false"

android:text="I have no white corners :-)"

android:textIsSelectable="true"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

... some other views

更新1

我尝试过Just89的解决方案,但是它导致较低的Android版本崩溃.

android.graphics.drawable.ColorDrawable cannot be cast to android.support.v7.widget.RoundRectDrawableWithShadow

答案建议使用:setCardBackgroundColor设置背景颜色.

然而,这将带回白色角落.

更新2

接受的答案将解决这个问题,但它不是首选的解决方案.我在创建导致这些白色角落的自定义CardView组件时犯了一个错误.检查this答案,看看我做错了什么.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值