Android: Change Shape Color in runtime

I’m now creating a Drawable like the one pre-compiler.. as i couldn’t change the color to anything but black, even after trying the hex OR described below.

The new code:

ShapeDrawable footerBackground = new ShapeDrawable();

// The corners are ordered top-left, top-right, bottom-right,
// bottom-left. For each corner, the array contains 2 values, [X_radius,
// Y_radius]
float[] radii = new float[8];
radii[0] = activity.getResources().getDimension(R.dimen.footer_corners);
radii[1] = activity.getResources().getDimension(R.dimen.footer_corners);

radii[2] = activity.getResources().getDimension(R.dimen.footer_corners);
radii[3] = activity.getResources().getDimension(R.dimen.footer_corners);

footerBackground.setShape(new RoundRectShape(radii, null, null));

int color = ((Application) activity.getApplication()).getColor();

footerBackground.getPaint().setColor(color);

views.setBackgroundDrawable(footerBackground);

Anyway this is a fix.. a solution for the first question is what i’m really looking for! I’ll appreciate any help of course!

Leave a Comment