Simple and plain buttons can do the job triggering some events in Android. But if you want to add more flavor and design to your UI, you can customize your buttons. Customization may include adding an image for your button, changing its image when pressed and/or displaying another image if it is focused.
In this section, we will create a simple customized button.
Here is an example that will show a customized button with three different image. The image will change depending on the state of the button.
Create a new project named HelloCustomButton. Below is the project structure of your new project.
Create/edit the layout so that it will display the customized button.
Create the customized button xml file as drawable.
Update the java source code so that it can handle the click event for the button.
Make sure to import the following:
Run the HelloCustomButton project and try clicking on the button to see the image change and the message displayed.