Как сделать круглую кнопку в android studio
Перейти к содержимому

Как сделать круглую кнопку в android studio

  • автор:

Rounded Button in Android Studio

There is no default attribution to make a button round in Android Studio. So to do that we have to add a new XML file to make the button round.

Drawable > New > Drawable Resource File (example: rounded_corner.xml)

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 ” .

How to make the corners of a button round in Android?

This example demonstrates how to make the corners of a button round in Android.

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.

Step 2 − Add the following code to res/layout/activity_main.xml.

Step 3 − Add the following code to src/MainActivity.java

Step 4 − Add the following code to res/drawable/mybutton.xml.

Step 5 − Add the following code to Manifests/AndroidManifest.xml

Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from the android studio, open one of your project's activity files and click Run icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen −

Creating Rounded Corner Button In Android Studio

Creating a rounded button in android studio is not so hard. In this android studio tutorial we will learn how to create rounded buttons with different styles. We also create the icon button which can be on the left or right side of the button.

Rounded buttons in android are mostly used because these look good and match with the design of the screen and the theme color. Most of the app screens use round corners buttons.

button in android studio

Button In Android Studio

Buttons in android studio are used to perform some task when we tap or press on it. These are the parts of GUI which have the feature of tapping or clicking. They call any function or move to another screen or can do anything which we want to perform. Rounded Buttons are also the same button in android studio, we provide the radius of the corners of the button so it becomes a rounded button.

By default android studio provides a Button widget which we can use but we can not provide rounded corners of it. We have to create a drawable design to make it rounded corners.

Default Button Of Android Studio

button in android studio

In the above screen there is a simple button we can not round its corners. We can change its background color and other properties. This is the default button in android studio.

Creating Rounded Corner of The Simple Button in android Studio

To create the rounded corner of the default Button provided by the android studio, we have to create a Drawable layout as follows and use as below in the button attribute.

Create a drawable layout inside the Drawable directory. Copy and paste following code you can change the background color and radius.

rect_rounded_button.xml

Now use as below in Button attribute.

rounded button in android studio

How to Change The Background Color of Default Button in Android Studio

Use following code to change the background color of default button in android studio.

button in android

Material Design Button in Android Studio

The other type of button is Material design Button in android. These buttons are designed by the material design library anyone can use this button and its other designs.

You should be happy to read that the material design button has the attribute of round shape that is easy to use. There are many other features which are more that the default button of android studio.

Material Design Dependency

Add the following material design library in your build,gradle file. Higher versions of android studio already have this material design library.

Use MaterialButton widget in your layout file.

Rounded Corners of Material Button

Use following attribute to provide radius of corners.

How to Change the Background Color of Material Design Button

To change the background color of the material design button use the following feature inside the Material Button widget.

Complete code of Material Rounded Button in Android Studio

Use the following code to create the rounded corner button in your android project. You can see more features on the material design website.

material button in android

Click Event On Button

SetOnClickListener() used to create a Tap or Click event. Write setOnclick and you will see dropdowns, select setOnclickListener from there and write new and capital O in parantheses and select the method from dropdown. Use following code for button click event.

Please comment if this tutorial is helpful to you even if there is any issue in this code.

We suggest you to learn android DataBinding in android which is most useful for android developers. DataBinding is easy and simple to learn.

Learn more Android and Flutter tutorials which will improve your development skills.

Как сделать круглую кнопку в android studio

There is no default attribution to make a button round in Android Studio. So to do that we have to add a new XML file to make the button round.

Drawable > New > Drawable Resource File (example: rounded_corner.xml)

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 ” .

На рисунке:
Как сделать так чтоб клики по красной области не обрабатывались? 26627a046b8249deb77719e96da5872c.png

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.

23 Answers 23

Create an xml file named roundedbutton.xml in drawable folder

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.

If using Android Studio you can just use:

this works fine for me, hope this helps someone.

user avatar

Create a drawable/button_states.xml file containing:

Use it in button tag in any layout file

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

user avatar

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

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 .

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

user avatar

and add this to the button code

Used the shape as oval. This makes the button oval

user avatar

You can make a ImageButton with circular background image.

use ImageButton instead of Button.

and make Round image with transparent background

user avatar

You can use a MaterialButton :

and apply a circular ShapeAppearanceOverlay with:

enter image description here

For a round button create a shape:

use it as a background of your button link

Just use the MaterialButton

  • width equal height
  • cornerRadius is half of the width or height

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

You can use google’s FloatingActionButton

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

user avatar

I like this solution

user avatar

look into built in android drawables:

  1. Use the Image Buttons and make the background as the image you want.
  2. Create the images from the android asset studio link —

and download it, extraxt it , inside that look for mipmap-hdpi folder.

copy the image from the mipmap-hdpi folder and paste it in the drwable folder of your android project.

Now set the background as that image.

I went through all the answers. But none of them is beginner friendly. So here I have given a very detailed answers fully explained with pictures.

Open Android Studio. Go to Project Window and scroll to drawable folder under res folder

enter image description here

Right click, select New —> drawable resource folder

enter image description here

In the window that appears, name the file rounded_corners and click on OK

enter image description here

A new file rounded_corners.xml gets created

Open the file. You are presented with the following code —>

enter image description here

Replace it with the following code —>

enter image description here

Here the design view can be seen on the right side

Adjust the value in android:radius to make the button more or less rounded.

Then go to activity_main.xml

Put the following code —>

Here I have placed the Button inside a RelativeLayout . You can use any Layout you want.

For reference purpose MainActivity.java code is as follows —>

I have a Pixel 4 API 30 avd installed. After running the code in the avd the display is as follows —>

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *