Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Can I set a radius programmatically to a ShapeDrawable?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
180 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...