是否可以在自定義適配器中設置ListView/ExpandableListView的backgroundResource
和backgroundColor
。Android設置背景資源和顏色
我有一個透明PNG,將作爲可擴展列表視圖中的每一行的邊框。這個圖像只是一個內部陰影和底部的邊界。
我們的目標是做這樣的事情:
當我設置backgroundResource然後的backgroundColor,只有兩個節目最多的一個。我無法獲取資源來覆蓋顏色。有誰知道這是否可能?
這裏是我的代碼以獲得更好的主意:
private int[] colors2= new int[] { Color.parseColor("#e2e8e9"), Color.parseColor("#f1f2f2") };
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ViewHolder holder;
ExpandListGroup group = (ExpandListGroup) getGroup(groupPosition);
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater inf = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inf.inflate(R.layout.expandlist_group_item, null);
holder.title = (TextView) convertView.findViewById(R.id.tvGroup);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
int colorPos = groupPosition % colors.length;
convertView.setBackgroundResource(R.drawable.row_forground);
convertView.setBackgroundColor(color2[colorPos]);
holder.title.setText(group.getName());
return convertView;
}
我真的這樣做,查看色的最佳組合在我的程序中。我在Photoshop中嘲笑的東西並沒有在設備上渲染,所以我想找到一種簡單/快速的方式來改變顏色,而不必重新編寫.9.png文件。但是我最終使用了一個圖層列表,然後設置drawable。 – meepz 2012-08-15 23:39:00