2017-04-19 102 views
-1

我一直坚持以下问题。我有一个'正常'卡片视图,显示在有趣的不同灰色的颜色。我不知道为什么。 它看起来像这样: enter image description hereCardview显示灰色和棕色颜色recyclerview - android

为什么它不是正常的白色?

下面是item_row

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     app:cardCornerRadius="5dp" 
    > 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_margin="5dp"> 
      <TextView 
       android:id="@+id/textViewItemName" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_toLeftOf="@+id/checkBox" 
       android:layout_toStartOf="@+id/checkBox" 
       android:textColor="#000" 
       android:layout_centerVertical="true" 
       android:text="TextView" /> 

      <CheckBox 
       android:id="@+id/checkBox" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" 
       android:text="" /> 

     </RelativeLayout> 
    </android.support.v7.widget.CardView> 

</LinearLayout> 

在这里,XML是该活动的layout_content:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/content_choose" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.apps.reuven.choosepicture.ChoosePicturesToDisplayActivity" 
    tools:showIn="@layout/activity_choose_to_display"> 


    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerViewToDisplay" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    </android.support.v7.widget.RecyclerView> 





    </RelativeLayout> 

在清单 机器人主题:主题= “@风格/ AppTheme”>

这是...

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

回答

1

你的主题改成这样:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 
+0

谢谢。很简单。 – RJB

+0

我会尽我所能 – RJB

1

您使用的是Dark主题Theme.AppCompat.NoActionBar这就是为什么你的观察背景颜色显示变暗。

尝试使用Light主题Theme.AppCompat.Light.NoActionBar

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style>