CardView 在 Theme.AppCompat.NoActionBar时 一些问题

来源:互联网 发布:java常用算法手册豆瓣 编辑:程序博客网 时间:2024/06/04 23:21

问题一:背景色默认变成了黑色

查看CardView源码:

int backgroundColor;if (a.hasValue(R.styleable.CardView_cardBackgroundColor)) {    backgroundColor = a.getColor(R.styleable.CardView_cardBackgroundColor, 0);} else {    // There isn't one set, so we'll compute one based on the theme    final TypedArray aa = getContext().obtainStyledAttributes(COLOR_BACKGROUND_ATTR);    final int themeColorBackground = aa.getColor(0, 0);    aa.recycle();    // If the theme colorBackground is light, use our own light color, otherwise dark    final float[] hsv = new float[3];    Color.colorToHSV(themeColorBackground, hsv);    backgroundColor = hsv[2] > 0.5f            ? getResources().getColor(R.color.cardview_light_background)            : getResources().getColor(R.color.cardview_dark_background);}


所以此时最简单的方法是设置CardView的背景色:

app:cardBackgroundColor="@color/white"

还可以编写Theme.AppCompat.NoActionBarstyle 修改colorBackground属性:

<style name="AppTheme.Simple" parent="Theme.AppCompat.NoActionBar">    <item name="android:colorBackground">@color/white</item></style>

问题二:selectableItemBackgroundBorderless颜色很淡


可以编写Theme.AppCompat.NoActionBarstyle 修改属性

android:colorControlHighlight
为更深一点的颜色即可:


<style name="AppTheme.Simple" parent="Theme.AppCompat.NoActionBar">    <item name="android:colorBackground">@color/white</item>    <item name="android:colorControlHighlight">@color/theme_bg_grey</item></style>



0 0
原创粉丝点击