Sunday, December 5, 2010

Setting Solid Color to DrawableShape loaded from XML

So yea, tried to set a solid color to a ShapeDrawable resource loaded from XML
initially tried:

ShapeDrawable drawable = (ShapeDrawable)getResources().getDrawable(R.drawable.shape)
drawable.getPaint().setColor(color);

Didn't work,

So cast to GradientDrawable instead:
GradientDrawable drawable = (GradientDrawable)getResources().getDrawable(R.drawable.shape)
drawable.setColor(color);

No comments:

Post a Comment