Reputation: 867
I want to draw a perfect circular button. I tried using the following code:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<stroke
android:width="3dip"
android:color="#065a32" />
<corners android:radius="10dip"/>
<solid android:color="#eaebec" />
</shape>
But i was only able to draw an oval shape, even if i change the parameter:
<stroke
android:width="3dip"/>
<corners android:radius="10dip"/>
My Screenshot:
I already tried different links of this site but none of them fulfill my need.
Edit:
My code for getView() is:
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (convertView == null) {
LayoutInflater vi = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.calendar_item, null);
}
view.setBackgroundResource(R.drawable.calendar_cell_clicked);
}
Upvotes: 5
Views: 6940
Reputation: 2383
In your drawable folder create the following
circular_button.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:innerRadius="15dp"
android:thickness="10dp"
android:useLevel="false">
<solid android:color="#ce2c2c" />
</shape>
add the below attribute to any button to make it circular
android:background="@drawable/circular_button"
Output
Upvotes: 0
Reputation: 16
use this xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#9F2200"/>
<stroke android:width="2dp" android:color="#fff" />
</shape>
and in your layout
android:background="@drawable/button"
Upvotes: 0
Reputation: 1996
use this xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid
android:color="#eaebec" />
</shape>
and in your layout where you are setting background use
android:layout_width="50dp"
android:layout_height="50dp"
or whatever size you need the circle to be.
Upvotes: 9