ono
ono

Reputation: 3102

CircularImageView with a solid color

The CircularImageView, https://github.com/Pkmmte/CircularImageView, works great when setting an image bitmap like so...

circularImageView.setImageBitmap(bitmap);

However, there are times where I just want to set a solid color instead of a bitmap. If I do something like this,

circularImageView.setBackgroundResource(R.color.blue);

The color of the view is set but the image is never made circular, so it fill the entire rectangular view. I'm assuming the getDrawable() is returning null so it can't actually manipulate the view. Anyone ran into this problem or any suggestions on what to do?

Edit:

I can do this but it seems a bit flimsy:

Bitmap image = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
image.eraseColor(android.graphics.Color.GREEN);
circularImageView.setImageBitmap(image);

Upvotes: 4

Views: 390

Answers (2)

Onur A.
Onur A.

Reputation: 3017

Give a try for ColorDrawable;

int decode = Integer.decode("FF6666");
ColorDrawable colorDrawable = new ColorDrawable(decode);

Upvotes: 1

Karakuri
Karakuri

Reputation: 38595

You should call circularImageView.setImageResource(R.color.blue) instead.

The code you wrote sets the background of the view, not the content image. Looking at the code on github, this view will only clip the content image to the circle--it has no effect on the background at all.

Upvotes: 2

Related Questions