是否可以在自定义适配器中设置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