Recyclerview 项目行背景颜色问题
Recyclerview item row background color issues
我正在使用 recyclerview 列出来自 sql 的项目,我对项目行的背景颜色有疑问...我尝试更改它但没有任何反应。
这是我的行布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:background="@color/bg_main"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:padding="10dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/default_avatar"/>
<RelativeLayout
android:padding="10dip"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:textSize="18sp"
android:textColor="@color/text_color_black"
android:id="@+id/opponentsName"
android:text="Roger Nkosi"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_marginTop="5dp"
android:textSize="14sp"
android:textColor="@color/brownish_gray"
android:id="@+id/callStatus"
android:text="Roger Nkosi"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="@+id/dateCallMade"
android:layout_alignParentRight="true"
android:text="14:00"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
这是我片段的布局
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_main"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".view.fragments.PrivateVoiceCallsDialogFragment">
<!-- A RecyclerView with some commonly used attributes -->
<android.support.v7.widget.RecyclerView
android:scrollbars="vertical"
android:id="@+id/voice_recycler_view"
android:layout_height="match_parent"
android:layout_width="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
*bg_main 是一种简单的白色,有或没有它,行项目都是深色的...
在您的 cardView 组件中使用 cardBackgroundColor
属性,它将执行所需的操作。
我认为 CardView 与您的父 linearLayout 重叠,因此您看不到颜色。在 CardView 上使用 cardBackgroundColor
属性 或更改其子 linearLayout
的背景颜色
我正在使用 recyclerview 列出来自 sql 的项目,我对项目行的背景颜色有疑问...我尝试更改它但没有任何反应。
这是我的行布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:background="@color/bg_main"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:padding="10dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/default_avatar"/>
<RelativeLayout
android:padding="10dip"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:textSize="18sp"
android:textColor="@color/text_color_black"
android:id="@+id/opponentsName"
android:text="Roger Nkosi"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_marginTop="5dp"
android:textSize="14sp"
android:textColor="@color/brownish_gray"
android:id="@+id/callStatus"
android:text="Roger Nkosi"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="@+id/dateCallMade"
android:layout_alignParentRight="true"
android:text="14:00"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
这是我片段的布局
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_main"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".view.fragments.PrivateVoiceCallsDialogFragment">
<!-- A RecyclerView with some commonly used attributes -->
<android.support.v7.widget.RecyclerView
android:scrollbars="vertical"
android:id="@+id/voice_recycler_view"
android:layout_height="match_parent"
android:layout_width="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
*bg_main 是一种简单的白色,有或没有它,行项目都是深色的...
在您的 cardView 组件中使用 cardBackgroundColor
属性,它将执行所需的操作。
我认为 CardView 与您的父 linearLayout 重叠,因此您看不到颜色。在 CardView 上使用 cardBackgroundColor
属性 或更改其子 linearLayout