制作一些足球应用程序,我有几个活动,碎片和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颜色变回黑色.