[英]Android change TextView Font color in a ListView for a condition
I have same problem as Change the color of a specified item in a listview for android answered by Kartheek (Thank you) and adapted for testing as follows: 我遇到的问题与更改由Kartheek回答的Android列表视图中指定项目的颜色 (谢谢)并适用于测试如下:
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;
}
};
Question: I rather change font Color but view1.setTextColor(Color.parseColor("#E0E0EF"); does not seem to work; 问题:我宁愿更改字体颜色,但view1.setTextColor(Color.parseColor(“#E0E0EF”);似乎不起作用;
Looks like you missed the last closing ')' in your command. 看起来您错过了命令中的最后一个结束符')'。 Otherwise it seams correct:
否则,它说明正确:
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;
}
Show Us db_msg this layout in that layout there is one TextView just get the name of that and replace with "tvIDFrom_db_msg_layout" this 向我们展示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;
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.