How can I programmatically change the color (#000000
) of a shape in a layer list?
Here is my layer list:
You can also get the drawable or background of the view and set it as follows.
LayerDrawable layerDrawable = (LayerDrawable) view.getDrawable(); //view.getBackground()
GradientDrawable gradientDrawable = (GradientDrawable) layerDrawable
.findDrawableByLayerId(R.id.layer_list_item_id);
gradientDrawable.setColor(ContextCompat.getColor(getContext(), R.color.colorPrimary));