I have a simple listView with 4 textview as items and I want to change the background color of each item in the listView programatically. It is important for my case to not be limited by pre-compiled color values or states, and the solution must imply changing background color after the listView has been displayed.
Is this possible, how?
So far I've tried stuff like:
listView.getAdapter().getView(0, null, null)..setBackgroundColor(Color.GREEN);
or
listView.getAdapter().getView(0, listView.getAdapter().getView(i, null, null), null).setBackgroundColor(Color.GREEN);
also invalidated views after this lines, but it does not work.
Best Regards.
overwrite getview in listadapter
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
TextView title = (TextView) v.findViewById(R.id.title);
Color mColor = new Color();
mColor.red(redvalue);
mColor.green(greenvalue);
mColor.blue(bluevalue);
title.setTextColor(mColor);
OR
mColor.parseColor("#rrggbb")
title.setTextColor(mColor);
....
...
return v;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.