Can I set a radius programmatically to a ShapeDrawable?
Asked
Active
Viewed 1,479 times
0
-
check this : http://stackoverflow.com/a/27980783/4148757 – bhaskar kurzekar Mar 27 '17 at 06:41
2 Answers
6
You can do it like this:
public static void customView(View v, int backgroundColor, int borderColor)
{
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setCornerRadii(new float[] { 8, 8, 8, 8, 0, 0, 0, 0 });
shape.setColor(backgroundColor);
shape.setStroke(3, borderColor);
v.setBackgroundDrawable(shape);
}
You can use this function throughout your app and can put border and background color of your choice.
1
try this:
LayerDrawable bgDrawable = (LayerDrawable) btnCallnow.getBackground();
final GradientDrawable shape = (GradientDrawable) bgDrawable.findDrawableByLayerId(R.id.shape_id);
shape.setCornerRadius(5.0f);

Divyesh Patel
- 2,576
- 2
- 15
- 30