簡體   English   中英

列表視圖項目背景色

[英]List view item background color

您好,我如何才能從該數組設置項目襯板布局背景顏色,使其只有3種顏色,一種顏色一種,第二種顏色兩種,第三種顏色三種,然后一種顏色一種,等等。

列表視圖的位置

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

您可以嘗試創建自己的自定義適配器並實現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;

}

嘗試看一下這篇文章: 在適配器getView方法中更改當前listview項目的背景顏色

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM