CardView
的默认白色背景有问题,还是我遗漏了什么?当我用普通的无样式 Android UI 填充 CardView
时,TextView
的白色文本不可读,例如
有人知道解决这个问题的好办法吗?我使用默认的“Theme.AppCompat”主题,其他背景颜色看起来正确。这是 Theme.AppCompat 中缺少的属性吗?还是我做错了什么?没有手动设置任何值的默认颜色应该始终有效吗?
编辑:
我现在将当前样式的默认背景颜色应用到卡片 View ,如下所示:
TypedArray array = context.getTheme().obtainStyledAttributes(
new int[] { android.R.attr.colorBackground });
card.setCardBackgroundColor(array.getColor(0, 0xFF00FF));
我认为它是一个相当节省的“默认”修复,至少没有像屏幕截图中那样的文本颜色问题,但问题仍然是这里的最佳实践应该是什么,以及为什么 cardview 始终将白色作为默认背景颜色,无论使用什么主题..
最佳答案
通过这种方式你可以改变Cardview的背景颜色,
RoundRectDrawable backgroundDrawable = new RoundRectDrawable(backgroundColor, cardView.getRadius());
cardView.setBackgroundDrawable(backgroundDrawable);
关于android - CardView 默认背景色有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27100497/