使一些足球的應用程序,我有幾個Activities
,Fragments
和RecyclerViews
,但只是在我的文字這一情況下改變顏色: 文字RecyclerView TextView的顏色改變
的片段顯示適當的標誌和名稱。
但在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, parent, false);
viewHolder = new ViewHolder3(view);
}
return viewHolder;
}
在onBind我只是叫.setText到TextView的,沒有什麼不尋常那裏。 Holder類:
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的'getView()'方法。最有可能的是,當你擴充你的XML佈局時,你傳遞'null'作爲父'ViewGroup'。 – JonasCz 2015-03-02 19:23:32
或...只需在XML中爲TextView設置'android:textColor'屬性即可。 – JonasCz 2015-03-02 19:26:50
getView()?這是ListView的事情。你的意思是onCreateViewHolder,我用更多的代碼編輯了帖子。 'android:textColor'是解決方法,我想知道爲什麼我會遇到這個問題 – Gudin 2015-03-02 19:58:43