列表视图项背景颜色

时间:2017-10-14 19:23:09

标签: java android listview

你好我如何设置项目衬里布局背景颜色从这个数组只有3种颜色,位置一种颜色一种,位置两种颜色两种,位置三种颜色三种然后定位一种颜色等等。 / p>

列表视图的位置

int[] androidColors = context.getResources().getIntArray(R.array.randomColor);
    viewHolder.linearLayout.setBackgroundColor(androidColors[position]); 

1 个答案:

答案 0 :(得分:0)

您可以尝试创建自己的自定义适配器并实现这样的getView函数:

public View getView (int position, View convertView, ViewGroup parent){
if( convertView == null ){
    //We must create a View:
    convertView = inflater.inflate(R.layout.my_list_item, parent, false);
}
//Here we can do changes to the convertView, such as set a text on a TextView or set the color of every single item of your view.
//or an image on an ImageView.
return convertView;

}

试着看一下这篇文章: Change background colour of current listview item in adapter getView method