android - CardView suddenly turned black -
i've got problem cardview in recyclerview.  cardview became black , ratingbar became blue. i'm using infiniterecyclerview changing simple recyclerview has no effect. can change cardview's background colour white ratingbar still blue. example of happening:
i use normal recyclerview in activity within fragment same adapter , looks fine. here example:
this single_recipe_recycler_item.xml layout file:
<?xml version="1.0" encoding="utf-8"?>  <android.support.v7.widget.cardview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginleft="5dp" android:layout_marginright="5dp" android:layout_margintop="5dp">  <linearlayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:background="?android:attr/selectableitembackground"     android:orientation="horizontal">      <imageview         android:id="@+id/recipe_recycler_image"         android:layout_width="80dp"         android:layout_height="match_parent"         android:layout_gravity="center_vertical"         android:src="@mipmap/ic_launcher" />      <relativelayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:paddingbottom="5dp"         android:paddingleft="10dp"         android:paddingright="10dp"         android:paddingtop="5dp">          <!-- realmrecipe title -->         <textview             android:id="@+id/recipe_recycler_title"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignparentend="true"             android:layout_alignparentright="true"             android:gravity="end"             android:text="very very very long title"             android:textcolor="@color/colorblack"             android:textsize="@dimen/title"             android:textstyle="bold" />          <!-- publisher -->         <textview             android:id="@+id/recipe_recycler_publisher"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignparentend="true"             android:layout_alignparentright="true"             android:layout_below="@id/recipe_recycler_title"             android:layout_margintop="5dp"             android:text="publisher"             android:textcolor="@color/colorblack"             android:textsize="@dimen/genre"             android:textstyle="italic" />          <!-- rating -->         <ratingbar             android:id="@+id/recipe_recycler_rating_bar"             style="@style/widget.appcompat.ratingbar.small"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignparentend="true"             android:layout_alignparentright="true"             android:layout_below="@id/recipe_recycler_publisher"             android:layout_margintop="5dp"             android:isindicator="true"             android:max="5" />      </relativelayout>  </linearlayout>  </android.support.v7.widget.cardview> this apptheme:
<style name="apptheme" parent="theme.appcompat.light.noactionbar">     <!-- customize theme here. -->     <item name="colorprimary">@color/colorprimary</item>     <item name="colorprimarydark">@color/colorprimarydark</item>     <item name="coloraccent">@color/coloraccent</item> </style> why happening? there bug in cardview? suggestions on how fix this?
i encountered same issue , here how solved it. make sure adapter inflates layout follows. understand better let's call adapter myadapter
@override public view getview(int position, view view, viewgroup parent) {     if (view == null){         layoutinflater layoutinflater = (layoutinflater) getcontext()                 .getsystemservice(activity.layout_inflater_service);         view = layoutinflater.inflate(r.layout.recycler_row_layout_person, null, true);      } then activity in you'll using adapter, make sure you're using right context. we'll using myadapter in activity called myactivity. wrong ways use layout inflator wrong context follows
- first wrong way - myadapter adapter = new myadapter( getapplicationcontext(), r.layout.recycler_row_layout_person, arraylist );
- second wrong way - myadapter adapter = new myadapter( getcontext(), r.layout.recycler_row_layout_person, arraylist );
here's right way it. , way solved it.
myadapter adapter = new myadapter(                                  myactivity.this, r.layout.recycler_row_layout_person, arraylist                          ); i hope helps
Comments
Post a Comment