In this post, we want to discuss 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 resources (style). Now we create a drawable resource file by “button.xml” named for each of the four button states under the drawable folder in Android Studio. Repeated that, every file of them must be under the drawable 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

The article was published on October 21, 2016 @ 11:20 PM

Leave a Comment