I solved this myself, but the workaround infuriated me; i hope this may be of use to someone. I'll post the solution below...
I'm using the package
import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;
To define a custom adapter
public class MyCustomStickyListAdapter extends BaseAdapter implements StickyListHeadersAdapter, Filterable
{ ... }
to display a filtered list of (for example) Movies, and depending on some criteria I want to color the row multiple colors.
For each failing criteria I want to add a default color white instead of the passing color green, red, pink.
In my getView() method; before I return my convertView I set my view's background color using a method...
private void setViewCompositeBackgroundColor(View convertView, ColorDrawable[] colors){
LayerDrawable background = new LayerDrawable(colors);
for(int i = 0; i < colors.length; i++)
{
background.setLayerInsetLeft(i, (i * windowWidth) / colors.length);
background.setLayerInsetRight(i, windowWidth - (((i + 1) * windowWidth) / colors.length));
}
convertView.setBackground(background);
}
The ColorDrawables are class variables and I define them in the constructor...
colorDefault = new ColorDrawable(ContextCompat.getColor(context, R.color.colorDefault));
etc...
If I pass two colors to this method with the same Color ID (two "default" white colors) then it will move all of the left layers with the same color ID to the position of the rightmost layer; I checked this by making the layers opaque and using a color other than white for the default and noticed that if two default criteria were met, then the rightmost layer was the darkest and the left layers remained the default ListView color.
I defined an .xml values file with the colors like so...
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="green">@color/Green</color>
<color name="red">@color/red</color>
<color name="pink">@android:color/pink</color>
<color name="default">@color/White</color>
</resources>
For example, if the first two criteria resolve to default white. And a third criteria resolves to pink
it looks like this (grey is just the default ListView background color)...
Actual
But I want it to look like this... Expected
This was the workaround, I defined unique default colors, offset by 1hx.
For each layer that I wanted to use a default color white; I used a different shade of white and the ColorDrawables stopped moving themselves to the rightmost re-used color.