How to change shape color dynamically?
For me, it crashed because getBackground
returned a GradientDrawable
instead of a ShapeDrawable
.
So i modified it like this:
((GradientDrawable)someView.getBackground()).setColor(someColor);
You could modify it simply like this
GradientDrawable bgShape = (GradientDrawable)btn.getBackground();
bgShape.setColor(Color.BLACK);