How to Change the Shape of ImageButton in Android?
Android ImageButton is a user interface widget that is used to display a button having an image and to perform exactly like a button when we click on it but here, we add an image on the Image button instead of text. Below is a sample image of ImageButton.
In the android studio, the default shape of the ImageButton is square. In this article, we will see how to change the default shape from Square to the following shapes
- Square with curved edges
Step by Step Implementation
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Working with the activity_main.xml file
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. Create a simple ImageButton in the activity_main.xml file.
Step 3: Create Drawable Resource File
Go to the app > res > drawbe > right-click > New > Drawable Resource File and name the file as custom_button1, custom_button2, cutom_button3 and apply them one by one in ImageButton like this:
1. custombutton1.xml file (Circular)
2. custombutton2.xml file (Rectangular)
3. custombutton3.xml file (Square with curved edges)