Is it possible to set the backgroundResource
and backgroundColor
of a ListView/ExpandableListView in a custom adapter.
I have a transparent png that will serve as the border for each row in an expandable listview. This image is just an inner shadow and a border on the bottom.
The goal is to do something like this:
When I set the backgroundResource and then backgroundColor, only one of the two shows up. I can't get the resource to overlay the color. Does anyone know if this is possible?
Here is my code to get a better idea:
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;
}
setBackgroundResource
and setBackgroundColor
both use the same api setBackgroundDrawable
internally to do their tasks. So one overwrites the other. So you wont be able to achieve your goal using this api.
You will have to use setBackgroundResource with a custom drawable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With