How can I programmatically change the color (#000000
) of a shape in a layer list?
Here is my layer list:
First of all you need to assign id to you layer-list
item.
-
-
Then get your shape by id.
LayerDrawable shape = (LayerDrawable) getResources().getDrawable(R.drawable.your_shape)
And you can change the color of your shape by calling
shape.setColor(Color.Black); // changing to black color
EDIT
As getDrawable()
has been deprecated. Use the following line of code.
LayerDrawable shape = (LayerDrawable) ContextCompat.getDrawable(YourActivity.this,R.drawable.your_shape)