Reputation: 93
What I want to do is to draw a circle and fill it by one color (for example orange) and want to make a border in another color (blue) programmatically. I didn't find any tutorial on how to do this.
This is what I want to get:
Upvotes: 4
Views: 9045
Reputation: 24211
To achieve the circle drawable programmatically you need to have a function like the following.
public static GradientDrawable drawCircle(int backgroundColor, int borderColor) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.OVAL);
shape.setCornerRadii(new float[]{0, 0, 0, 0, 0, 0, 0, 0});
shape.setColor(backgroundColor);
shape.setStroke(10, borderColor);
return shape;
}
And set the drawable
in your ImageView
like the following.
imageView.setBackground(drawCircle(getResources().getColor(android.R.color.holo_blue_dark), getResources().getColor(android.R.color.holo_red_dark)));
This is giving something like this.
Upvotes: 11