Yes, you can change the shape color dynamically. Suppose your xml is included, 'res / drawable / oval_shape.xml'
GradientDrawable shape = (GradientDrawable) getResources().getDrawable(R.drawable.oval_shape); int argb = 0x12345678; shape.setBackground( argb );
if you want to change the color of the frame
int width = 1; int argb = 0x87654321; shape.setStroke( width, argb );
This solution provides more flexibility when using the level list because you are not tied to using the view to set the level.
source share