Draw circle shape in ImageView in Android

It is better practice to use less number of images in your android project to generate small apk file. This tutorial will help you to draw a circle of your size and set it to your ImageView or to any other View. We will use ShapeDrawable for this purpose.

Now we create ShapeDrawable of OvalShape by writing following line.

ShapeDrawable sd = new ShapeDrawable(new OvalShape());

Now we set height and width parameters of ShapeDrawable object.

sd.setIntrinsicHeight(100);
sd.setIntrinsicWidth(100);

The last thing is to set color to ShapeDrawable object.

sd.getPaint().setColor(Color.parseColor("#abcd123"));

You are ready to set this circle image to your Imageview.

ImageView iv = (ImageView) findViewById(R.id.iv);
iv.setBackground(sd);

Here is the full code.

ShapeDrawable sd = new ShapeDrawable(new OvalShape());
sd.setIntrinsicHeight(100);
sd.setIntrinsicWidth(100);
sd.getPaint().setColor(Color.parseColor("#abcd123"));
ImageView iv = (ImageView) findViewById(R.id.iv);
iv.setBackground(sd);