Making some soccer app, I have few Activities
, Fragments
and RecyclerViews
, but just in this one case colour of my text changed:
The fragment is displaying logo and name appropriately.
But in RecyclerView
, you can barely see name of players because it's so white, and 3 other small text are also hard to read.
It is looking like text changed it's color to fit to some black theme, while through my all app it is default Theme.AppCompat.Light.DarkActionBar
When editing everything looks fine:
and the code of one view holder also looks fine:
<?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: Some code from Adapter. I am using this adapter multiple times (case 0,1,2) and only in this one case it is changing the color of 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 to TextView, nothing unusual there. 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);
}
I just had the same problem, and it was because I was using in the RecyclerView
a LayoutInflater
created with the Context
of the Application
, instead of the current Activity
.
After changing it to create from the Activity
, the RecyclerView
colors went back to black.
Just set the android:textColor
attribute for your TextView
in your XML layout. This will let you change the color of the text as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With