23 June 2020   |   by Marshi Shastri   |   Android, Blogs

Creating a button in Android Studio

Creating a button in Android Studio

Steps to create a button in Android Studio

The following steps let you know about easily you can create a button.

1. Create an empty activity, in which we will create a button, design it and add functionality to it.

2. Drag and drop a button from the Palette present on the left of the window to the activity.

3. Set constraints from the constraint widget which is present in the attribute’s palette on the right of the window.

4. You can center the button in the activity by setting equal values of left and right constraints.

5. Setting the width, height and text of the button. We will set button width to 200dp, height to 50dp and text to “Click Me!”.

6. Setting text color for button. You can select the color with the help of color palette.

7. Or we can set the color of text by directly entering the hex code of color.

8. Setting the background color of the button.

9. Now, creating a function to run when the button is clicked.

10. Setting the onClick value of the button to the function ‘buttonClicked’ created just now.

Let’s run our app and check the working of the created button.