RecyclerView TextView text color changed

Having created some kind of football application, I have few Activities , Fragments and RecyclerViews , but only in this case the color of my text has changed: enter image description here

The fragment displays the logo and name accordingly.

But in RecyclerView you can hardly see the name of the players, because it is so white, and 3 more small texts are also difficult to read. It looks like text that changed its color to fit some black theme, and through my application by default - Theme.AppCompat.Light.DarkActionBar

When editing, everything looks fine:

enter image description here

and the code of one view holder also looks good:

 <?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"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:textStyle="bold" android:text="12: Tyler Blackett" android:id="@+id/txt_players_name" android:layout_marginLeft="12dp" android:layout_marginStart="12dp" android:layout_marginTop="8dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:text="Small Text" android:id="@+id/txt_players_position" android:layout_below="@+id/txt_players_name" android:layout_alignLeft="@+id/txt_players_name" android:layout_alignStart="@+id/txt_players_name" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:text="Small Text" android:id="@+id/txt_players_nationality" android:layout_below="@+id/txt_players_position" android:layout_alignLeft="@+id/txt_players_position" android:layout_alignStart="@+id/txt_players_position" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:text="Small Text" android:id="@+id/txt_players_value" android:layout_below="@+id/txt_players_nationality" android:layout_alignLeft="@+id/txt_players_nationality" android:layout_alignStart="@+id/txt_players_nationality" /> </RelativeLayout> 

EDIT: Invalid code from adapter. I use this adapter several times (case 0,1,2), and only in this case it changes the color of the text:

 public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view; RecyclerView.ViewHolder viewHolder = null; switch(viewType){ case 0: view = inflater.inflate(R.layout.row_teams, parent, false); viewHolder = new ViewHolder0(view); break; //working fine case 1: {...} //working fine case 2: {...} //working fine case 3: view = inflater.inflate(R.layout.row_players, parent, false); viewHolder = new ViewHolder3(view); } return viewHolder; } 

In onBind, I just call .setText in the TextView, there is nothing unusual. Holder Class:

 public class ViewHolder3 extends RecyclerView.ViewHolder { TextView mPlayerName; TextView mPosition; TextView mNationality; TextView mValue; public ViewHolder3(View itemView) { super(itemView); mPlayerName = (TextView) itemView.findViewById(R.id.txt_players_name); mPosition = (TextView) itemView.findViewById(R.id.txt_players_position); mNationality = (TextView) itemView.findViewById(R.id.txt_players_nationality); mValue = (TextView) itemView.findViewById(R.id.txt_players_value); } 
+6
source share
2 answers

I had the same problem, and precisely because I used in RecyclerView a LayoutInflater created using the Context Application , instead of the current Activity .

After changing it to create from Activity colors of the RecyclerView returned to black.

+11
source

Just set the android:textColor attribute for the TextView in your XML layout. This will allow you to change the color of the text as needed.

+1
source

Source: https://habr.com/ru/post/983232/


All Articles