ITPub博客

首页 > IT职业 > IT图书 > ClassCastException:ColorDrawable

ClassCastException:ColorDrawable

IT图书 作者:gabbro 时间:2021-09-09 09:10:17 0 删除 编辑
原标题:ClassCastException:ColorDrawable cannot be cast to RoundRectDrawableWithShadow 错误信息
java.lang.ClassCastException: android.graphics.drawable.ColorDrawable cannot be cast to android.support.v7.widget.RoundRectDrawableWithShadow

我在给CardView组件设置背景颜色属性时,起初是按照如下方法做的:

cardView.setBackgroundColor(Color.parseColor("#ffffff"));

但是运行后却报错,提示类型转换错误:java.lang.ClassCastException: android.graphics.drawable.ColorDrawable cannot be cast to android.support.v7.widget.RoundRectDrawableWithShadow

解决方案
cardView.setCardBackgroundColor(Color.parseColor("#ffffff"));

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2873/viewspace-2799788/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-19

  • 博文量
    85
  • 访问量
    726