2017-06-22 295 views
0

我正在使用recyclerview列出來自sql的項目,我遇到了項目行的背景顏色問題......我試圖改變它,但沒有任何反應。Recyclerview項目行背景顏色問題

這是我行佈局

<?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是一個簡單的白色,帶或不帶它的行項目是黑暗...

+0

嘗試使用此應用程序:cardBackgroundColor =「@ color/colorPrimary」 – MRX

+0

謝謝我已經使用它,它的工作原理非常感謝。 –

回答

0

我認爲CardView與你父母的linearLayout重疊,因此你看不到顏色。在CardView上使用cardBackgroundColor屬性或更改其子的背景顏色linearLayout

+0

它的工作原理。謝謝... –

0

在你的cardView組件中使用cardBackgroundColor屬性,它會做所需的事情。

+0

謝謝你,它的工作原理... –