android – RecyclerView TextView文本颜色改变了

前端之家收集整理的这篇文章主要介绍了android – RecyclerView TextView文本颜色改变了前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
制作一些足球应用程序,我有几个活动,碎片和RecyclerViews,但只是在这个案例中我的文字颜色改变了:

该片段正在显示徽标和名称.

但是在RecyclerView中,你几乎看不到玩家的名字,因为它太白了,其他3个小文字也难以阅读.
它看起来像文本改变它的颜色以适应一些黑色主题,而通过我的所有应用程序,它是默认的Theme.AppCompat.Light.DarkActionBar

编辑一切看起来很好:

并且一个视图持有者的代码看起来也很好:

<?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>

编辑:适配器的一些代码.我多次使用这个适配器(情况0,1,2),只有在这种情况下,它正在改变文本的颜色:

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,false);
                viewHolder = new ViewHolder3(view);
        }
        return viewHolder;
    }

在onBind中,我只需将.setText调用到TextView,没有什么不寻常的.
持有人类:

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);
        }

解决方法

我只是遇到了同样的问题,这是因为我在RecyclerView中使用了一个用应用程序的Context创建的LayoutInflater,而不是当前的Activity.

将其更改为从Activity创建后,RecyclerView颜色变回黑色.

原文链接:https://www.f2er.com/android/312936.html

猜你在找的Android相关文章