的Android变化TextView的字体颜色在ListView一个条件
问题描述:
我为Change the color of a specified item in a listview for android同样的问题,通过Kartheek(谢谢)回答适用于测试如下:的Android变化TextView的字体颜色在ListView一个条件
adapter = new ArrayAdapter<String>(this,R.layout.db_msg,messaggi){
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view1 = super.getView(position, convertView, parent);
// if (position % 2 == 0) { //Place the condition where you want
to change the item color.
testo = messaggi.get(position);
if(testo.substring(0,5).equals("27-09")){
view1.setBackgroundColor(Color.parseColor("#e0e0ef"));
} else {
//Setting to default color.
view1.setBackgroundColor(Color.WHITE);
}
return view1;
}
};
问题:我而改变字体颜色但view1.setTextColor(Color.parseColor(“#E0E0EF”);似乎没有工作;
答
显示,美国db_msg这种布局在布局有一个TextView中刚刚获得的这个名字与“tvIDFrom_db_msg_layout”这
adapter = new ArrayAdapter<String>(this,R.layout.db_msg,messaggi){
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view1 = super.getView(position, convertView, parent);
if (position % 2 == 0) { //Place the condition where you want to change the item color.
testo = messaggi.get(position);
TextView tvText = (TextView) view1.findViewById(R.id.tvIDFrom_db_msg_layout);
if(testo.substring(0,5).equals("27-09")){
tvText.setTextColor(Color.parseColor("#yourHexCode"));
} else {
//Setting to default color.
tvText.setTextColor(Color.WHITE);
}
return view1;
}
};
+0
是的,它的作品!我能使用tvText.setTextColor(Color.parseColor(” #0000ef“)); – alberto
答
看起来像你错过了最后关闭')'在你的命令。否则接缝正确:
view1.setTextColor(Color.parseColor("#E0E0EF"));
答
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view1;
view1=convertView;
if (convertView == null) {
view1 = inflater.inflate(R.layout.db_msg, null);
testo = messaggi.get(position);
if(testo.substring(0,5).equals("27-09")){
view1.setBackgroundColor(Color.parseColor("#e0e0ef"));
}
else {
//Setting to default color.
view1.setBackgroundColor(Color.WHITE);
}
return convertView;
}
写convertView更换.setBackgroundColor(Color.parseColor( “#e0e0ef”)); – Ankita
包含您的db_msg布局xml代码 – SiSa
向我们展示此布局R.layout.db_msg –