Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.

YouTube privacy policy

If you accept this notice, your choice will be saved and the page will refresh.

 

Show the video description

In this video we will learn how to create a custom button that uses image files to replace the background of the default Android button.
For this we will create a StateListDrawable xml file, where we define appropriate png files from the drawable folder for the different button state combinations of state_pressed and state_enabled. We put these states as items between a selector tag to create a state list and set it as the background on our Button widget.
Just like for any other button, we can set an OnClickListener on our custom button, disable it etc.

Downloadsactivity_main.xmlcustom_button.xmlMainActivity.java