enter image description here Когда я использую RecyclerView для отображения данных списка в своем приложении, я обнаружил, что backgourndcolor RecyclerView всегда был белым. Я устанавливаю backgroudcolor в xml-файле и коде, но он не работает. кто может сказать мне, почему? Большое спасибо!android RecyclerView BackgroundColor
//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"
}
добавить recyclerView в цвет фона настроенной Верстка на красный –
АРЕМ Вы уверены, что вы не добавляете никакого фона во время выполнения ?? –
@vabhi vab Цвет фона материнской платы RecyclerView также не отображался. – TonyChou