嘿,是否可以更改 ExpandableListView 中指定行的背景?我想要的是:第一行蓝色,第二行红色,第三行蓝色,第四行红色.....谢谢
最佳答案
是的,这是可能的,您必须为可扩展 ListView 使用自定义适配器。
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
//......
//...... Your code for row view
//.....
//Now write here code for set colors for rows
if(childPosition % 2 == 0) {
convertView.setBackgroundColor("#0000FF"); // use this when you want to use hexa value of colors
} else {
convertView.setBackgroundColor("#FF0000"); // use this when you want to use hexa value of colors
}
//setBackgroundResource(android.R.color.transparent); // use this for predefined colors at place of setBackground
return convertView;
}
阅读this文章,此处还提供示例和源代码。
关于java - 更改 ExpandableListView 中每一行的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5679538/