Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Circular Image View Background black in android?

Image View background reflect only inside the circle not outside the circle. I tried so many things but not able do that. Anybody please me. Thanks!!

like image 948
P. Jaiswal Avatar asked Sep 06 '17 08:09

P. Jaiswal


3 Answers

Make an .xml file in drawable folder with this content:

<?xml version="1.0" encoding="utf-8"?>
<shape
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:shape="oval">
     <solid
        android:color="@color/black"/>
</shape>

Then set this file as your background.

like image 111
Gotiasits Avatar answered Oct 21 '22 12:10

Gotiasits


circle.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
    <size android:width="50dp"
        android:height="50dp"/>
    <stroke
        android:width="3dp"
        android:color="@color/black"/>
    <solid android:color="@color/black"/>
</shape>

in ImageView add this in

android:background="@drawable/circle"

thank you everyone for the help. This code is working as I want. thank You!!

like image 7
P. Jaiswal Avatar answered Oct 21 '22 12:10

P. Jaiswal


I guess you're using CircularImageView custom imageview class to make it circular. That's why background it getting apllied in cicular region only.

To solve it, do something like this,

<LineaLayout
     android:width="wrap_content"
     android:height="wrap_content"
     android:orientation="vertical"
     android:background="@color/black"/>


<!-- your circular CircularImageView here..!! -->

</LinearLayout>

Other solution you can do is, Use native ImageView and set its android:src by creating circular bitmap and use android:background black color and i would suggest to go with thise solution as you can avoid nested layouts.

I hope this hepls! Thanks.

like image 1
Anand Dabhi Avatar answered Oct 21 '22 11:10

Anand Dabhi