Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RecyclerView TextView color of text changed

Tags:

android

Making some soccer app, I have few Activities, Fragments and RecyclerViews, but just in this one case colour of my text changed: enter image description here

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:

enter image description here

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);
        }
like image 303
JoKr Avatar asked Mar 02 '15 19:03

JoKr


2 Answers

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.

like image 151
Alvaro Gutierrez Perez Avatar answered Oct 18 '22 16:10

Alvaro Gutierrez Perez


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.

like image 34
JonasCz Avatar answered Oct 18 '22 15:10

JonasCz