Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a round button?

I'm trying to make a round button, but I don't know how can I do it. I can make button with rounded corners, but how can I can round circle. It's not the same. Please, tell me, is it possible on Android? Thank you.

like image 342
user1166635 Avatar asked Apr 22 '12 08:04

user1166635


People also ask

How do you make a rounded button?

To create a rounded button you have to make use of the border-radius CSS property. The higher the value for that property the more rounder the corners will be. You can use any CSS unit for the boorder-radius property. It can be pixels, ems, rems, percentages etc.

How do you make a round edge button?

Rounded corners HTML Buttons You can make rounded corners button by adding border-radius of 5px to 10px on HTML buttons.

How do you make a button circular in CSS?

Use the border-radius Property to Create a Circle Button in CSS. We can use the border-radius property to create a circle button in CSS. The property creates the rounded corners to the selected element by adding the radius to the element's corners.


17 Answers

Create an xml file named roundedbutton.xml in drawable folder

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle">
    <solid android:color="#eeffffff" />
    <corners android:bottomRightRadius="8dp"
        android:bottomLeftRadius="8dp"  
        android:topRightRadius="8dp"
        android:topLeftRadius="8dp"/>
</shape>

Finally set that as background to your Button as android:background = "@drawable/roundedbutton"

If you want to make it completely rounded, alter the radius and settle for something that is ok for you.

like image 99
Arif Nadeem Avatar answered Oct 07 '22 01:10

Arif Nadeem


If using Android Studio you can just use:

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

    </shape>

this works fine for me, hope this helps someone.

like image 33
Shaun Jones Avatar answered Oct 07 '22 03:10

Shaun Jones


  1. Create a drawable/button_states.xml file containing:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="false"> 
            <shape android:shape="rectangle">
            <corners android:radius="1000dp" />
            <solid android:color="#41ba7a" />
            <stroke
                android:width="2dip"
                android:color="#03ae3c" />
            <padding
                android:bottom="4dp"
                android:left="4dp"
                android:right="4dp"
                android:top="4dp" />
            </shape>
        </item>
        <item android:state_pressed="true"> 
            <shape android:shape="rectangle">
            <corners android:radius="1000dp" />
            <solid android:color="#3AA76D" />
            <stroke
                android:width="2dip"
                android:color="#03ae3c" />
            <padding
                android:bottom="4dp"
                android:left="4dp"
                android:right="4dp"
                android:top="4dp" />
            </shape>
        </item>
    </selector>
    
  2. Use it in button tag in any layout file

    <Button
        android:layout_width="220dp"
        android:layout_height="220dp"
        android:background="@drawable/button_states"
        android:text="@string/btn_scan_qr"
        android:id="@+id/btn_scan_qr"
        android:textSize="15dp"
    />
    
like image 34
Mohit Avatar answered Oct 07 '22 03:10

Mohit


Markushi's android circlebutton:

(This library is deprecated and no new development is taking place. Consider using a FAB instead.)

enter image description here

like image 37
LOG_TAG Avatar answered Oct 07 '22 03:10

LOG_TAG


If you want a FAB looking circular button and you are using the official Material Component library you can easily do it like this:

<com.google.android.material.button.MaterialButton
    style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
    app:cornerRadius="28dp"
    android:layout_width="56dp"
    android:layout_height="56dp"
    android:text="1" />

Result:

enter image description here

If you change the size of the button, just be careful to use half of the button size as app:cornerRadius.

like image 43
Roberto Leinardi Avatar answered Oct 07 '22 03:10

Roberto Leinardi


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

Set that on your XML drawable resources, and simple use and image button with an round image, using your drawable as background.

like image 42
Giovanny Piñeros Avatar answered Oct 07 '22 01:10

Giovanny Piñeros


<corners android:bottomRightRadius="180dip"
    android:bottomLeftRadius="180dip"
    android:topRightRadius="180dip"
    android:topLeftRadius="180dip"/>

<solid android:color="#6E6E6E"/> <!-- this one is ths color of the Rounded Button -->

and add this to the button code

    android:layout_width="50dp"
    android:layout_height="50dp"
like image 31
user4512768 Avatar answered Oct 07 '22 01:10

user4512768


Used the shape as oval. This makes the button oval

<item>
    <shape android:shape="oval" >
        <stroke
            android:height="1.0dip"
            android:width="1.0dip"
            android:color="#ffee82ee" />

        <solid android:color="#ffee82ee" />

        <corners
            android:bottomLeftRadius="12.0dip"
            android:bottomRightRadius="12.0dip"
            android:radius="12.0dip"
            android:topLeftRadius="12.0dip"
            android:topRightRadius="12.0dip" />
    </shape>
</item>

like image 39
Rohit Goyal Avatar answered Oct 07 '22 03:10

Rohit Goyal


You can use a MaterialButton:

     <com.google.android.material.button.MaterialButton
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:insetTop="0dp"
            android:insetBottom="0dp"
            android:text="A"
            app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.App.Rounded"
            />

and apply a circular ShapeAppearanceOverlay with:

<style name="ShapeAppearanceOverlay.App.rounded" parent="">
    <item name="cornerSize">50%</item>
</style>

enter image description here

like image 37
Gabriele Mariotti Avatar answered Oct 07 '22 02:10

Gabriele Mariotti


Round button in Android

You can make a ImageButton with circular background image.

like image 27
chavaone Avatar answered Oct 07 '22 02:10

chavaone


use ImageButton instead of Button....

and make Round image with transparent background

like image 38
MAC Avatar answered Oct 07 '22 01:10

MAC


For a round button create a shape:

<?xml version="1.0" encoding="utf-8"?>

<stroke
    android:width="8dp"
    android:color="#FFFFFF" />

<solid android:color="#ffee82ee" />


<corners
    android:bottomLeftRadius="45dp"
    android:bottomRightRadius="45dp"
    android:topLeftRadius="45dp"
    android:topRightRadius="45dp" />

use it as a background of your button link

like image 30
Naqash Avatar answered Oct 07 '22 01:10

Naqash


Yes it's possible, look for 9-patch on google. Good articles :

http://radleymarx.com/blog/simple-guide-to-9-patch/

http://ogrelab.ikratko.com/custom-color-buttons-for-android/

like image 33
jptsetung Avatar answered Oct 07 '22 02:10

jptsetung


Update 2021:

Just use the MaterialButton

<com.google.android.material.button.MaterialButton
    app:cornerRadius="30dp"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:text="test" />
  • width equal height
  • cornerRadius is half of the width or height
like image 28
Rasoul Miri Avatar answered Oct 07 '22 03:10

Rasoul Miri


You can use google's FloatingActionButton

XMl:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@android:drawable/ic_dialog_email" />

Java:

  @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    FloatingActionButton bold = (FloatingActionButton) findViewById(R.id.fab);
    bold.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
        // Do Stuff
        }
    });
}

Gradle:

    compile 'com.android.support:design:23.4.0'
like image 33
kalebora Avatar answered Oct 07 '22 03:10

kalebora


I simply use a FloatingActionButton with elevation = 0dp to remove the shadow:

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_send"
    app:elevation="0dp" />
like image 39
Florian Walther Avatar answered Oct 07 '22 03:10

Florian Walther


I like this solution

            <androidx.cardview.widget.CardView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:cardCornerRadius="18dp"
                app:cardElevation="0dp"
                >
                <ImageButton
                        android:layout_width="35dp"
                        android:layout_height="35dp"
                        android:background="@null"
                       android:scaleType="centerCrop"
              android:src="@drawable/social_facebook"
                        />
            </androidx.cardview.widget.CardView>
like image 23
djdance Avatar answered Oct 07 '22 01:10

djdance