Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the corners of a button round?

I want to make the corners of a button round. Is there an easy way to achieve this in Android?

like image 774
artist Avatar asked May 19 '11 06:05

artist


People also ask

How do you set a button corner radius?

Color and corner radius for the button can be modified as per your needs. The changes you make can be seen in the design option in the side: Now , in the main xml file where you want the rounded corners for the button , add this line : android:background=”@drawable/rounded_corner ” .

Should buttons have rounded corners?

Buttons with rounded corners are easier on the eyes than a rectangle with sharp edges because they take less cognitive effort to visually process. Scientific research done on corners by the Barrow Neurological Institute found that the “perceived salience of a corner varies linearly with the angle of the corner.

Why do buttons have rounded corners?

This is because many websites use a square, grid, or rectangular design, and the rounded edges create visual contrast which attracts instant attention. As the main role of any call to action button is to grab attention, and drive click throughs, the rounded rectangles can be incredibly effective.


2 Answers

Create a xml file in drawable folder like below

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle" android:padding="10dp">     <!-- you can use any color you want I used here gray color-->     <solid android:color="#ABABAB"/>      <corners android:radius="10dp"/> </shape> 

Apply this as background to button you want make corners round.

Or you can use separate radius for every corner like below

android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp" android:topLeftRadius="10dp" android:topRightRadius="10dp" 
like image 22
Sandip Jadhav Avatar answered Sep 26 '22 17:09

Sandip Jadhav


If you want something like this

Button preview

here is the code.

1.Create a xml file in your drawable folder like mybutton.xml and paste the following markup:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" >     <item android:state_pressed="true" >         <shape android:shape="rectangle"  >             <corners android:radius="3dip" />             <stroke android:width="1dip" android:color="#5e7974" />             <gradient android:angle="-90" android:startColor="#345953" android:endColor="#689a92"  />                     </shape>     </item>     <item android:state_focused="true">         <shape android:shape="rectangle"  >             <corners android:radius="3dip" />             <stroke android:width="1dip" android:color="#5e7974" />             <solid android:color="#58857e"/>                </shape>     </item>       <item >        <shape android:shape="rectangle"  >             <corners android:radius="3dip" />             <stroke android:width="1dip" android:color="#5e7974" />             <gradient android:angle="-90" android:startColor="#8dbab3" android:endColor="#58857e" />                    </shape>     </item> </selector> 

2.Now use this drawable for the background of your view. If the view is button then something like this:

<Button     android:id="@+id/button1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:padding="10dp"     android:textColor="#ffffff"     android:background="@drawable/mybutton"     android:text="Buttons" /> 
like image 87
Md. Monsur Hossain Tonmoy Avatar answered Sep 23 '22 17:09

Md. Monsur Hossain Tonmoy