android RecyclerView BackgroundColor

Lorsque j'utilise RecyclerView pour afficher la liste des données de mon application, le RecyclerView de backgroundcolor toujours été blanc:

android RecyclerView BackgroundColor

J'ai mis le backgroundcolor dans le fichier xml et le code, mais il ne fonctionne pas:

//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:background="@color/colorPrimary">
<!--<include layout="@layout/content_main" />-->
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
</LinearLayout>
//fragment_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent">
<android.support.v7.widget.RecyclerView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:padding="5dp" />
</RelativeLayout>
//item_layout.xml
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
card_view:cardBackgroundColor="@color/yellow"
card_view:cardCornerRadius="1dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
android:gravity="center"
android:textColor="@color/text_white"
android:textSize="@dimen/list_item_text_size" />
<ImageView
android:id="@+id/pic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/name"
android:scaleType="centerCrop" />
</RelativeLayout>
</android.support.v7.widget.CardView>
//gradle file
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.union.fmdouban"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
ajouter recyclerView dans une mise en page mise en page de la couleur d'arrière-plan rouge
Arem-vous sûr que vous n'ajoutez pas d'arrière-plan au moment de l'exécution ??
vab de la RecyclerView parent de la mise en page du backgroundcolor également à ne pas montrer.
Rakshit Nawani je n'ai pas mis de fond au moment de l'exécution .
Essayez de donner de la marge de votre adaptateur de mise en page peut-être votre adaptateur de mise en page n'a pas de marge et donc le recyclerView fond n'est pas visible

OriginalL'auteur TonyChou | 2016-03-14