In this post, we want to discuss about a nice function to change button style using shape on button state in Android. Before we get started, if you want to know about Listview binding in android, please go through the following article: How to bind simple Listview in Android.

How to Start

Every button has four states which are Enable, Focus, Press, Disable. If we want to change button style based on status, we should create four different drawable resource (style). Now we create a drawable resource file by “button.xml” named for each of the four button states under drawables folder in Android Studio. Repeated that, every file of them must be under drawables folder. You may copy the following code:

Code for button_enabled.xml
Code for button_focused.xml
Code for button_pressed.xml
Code for button_disabled.xml
Change button style using shape on button state in Android

Leave a Reply