[英]Change color of Textview in Listview
我是Android的新手,我想在Listview中更改TextView的文本顏色。 嘗試此操作時,顏色不會改變。 誰可以幫我解決這個(簡單?)問題?
我在“BaseAdapter”中使用以下代碼來控制ListView:
public View getView(int i, View view, ViewGroup viewGroup) {
if (view == null) {
view = mInflater.inflate(R.layout.cijfer_listitem, null);
holder = new ViewHolder();
holder.mCijferTxt = (TextView) view.findViewById(R.id.cijferTxt);
holder.mVakTxt = (TextView) view.findViewById(R.id.vakTxt);
holder.mVakUitgebreidTxt = (TextView) view.findViewById(R.id.vakUitgebreidTxt);
holder.mIdTxt = (TextView) view.findViewById(R.id.idTxt);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
Cijfer cijfer = mCijfers.get(i);
holder.mCijferTxt.setText(cijfer.getCijfer());
holder.mVakTxt.setText(cijfer.getCursus());
holder.mVakUitgebreidTxt.setText(cijfer.getCursusUitgebreid());
holder.mIdTxt.setText("" + cijfer.getCijferID());
if (cijfer.isDef() == true ){
holder.mCijferTxt.setTextColor(R.color.colorTxtDef);
}
else{
holder.mCijferTxt.setTextColor((R.color.colorTxtConcept));
}
return view;
}
public class ViewHolder {
public TextView mCijferTxt;
public TextView mVakTxt;
public TextView mVakUitgebreidTxt;
public TextView mIdTxt;
}
我想改變TextView“cijferTxt”的顏色。
希望這是足夠的信息,你可以幫助我:)
嘗試這個
holder.setTextColor(view.getResources().getColor(R.color.colorTxtDef));
您正在嘗試將文本顏色設置為顏色資源ID(這只是指向顏色的ID)。 您需要從此顏色資源ID中提取顏色。 例:
int color = context.getResources().getColor(R.color.colorTxtDef);
holder.mCijferTxt.setTextColor(color);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.