CircularImageView with solid color

CircularImageView, https://github.com/Pkmmte/CircularImageView , works great when setting up a bitmap like so ...

circularImageView.setImageBitmap(bitmap);

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

circularImageView.setBackgroundResource(R.color.blue);

The view color is set, but the image is never made circular, so it fills the entire rectangular view. I am assuming it getDrawable()

returns null, so it cannot actually manipulate the view. Has anyone encountered this problem or any suggestions on what to do?

Edit:

I can do this, but it seems a little flimsy:

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

      

+3


source to share


2 answers


Instead, you must call circularImageView.setImageResource(R.color.blue)

.



The code you wrote sets the background of the view, not the content image. Looking at the code on github, this view will only copy the content image to the circle - it doesn't affect the background image at all.

+2


source


Try it ColorDrawable

;



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

      

+1


source







All Articles