Loading...

How to Change Android Button on Click/Press Color

In this simple tip, I’m going to show how to change android button on click or press color. If you want to change the click or press color of TextView or any android Layout you can do same way. Android Button onClick Event teaches you to handle button click and you can find different android button style at Android Button Examples.

Related:
Android Elevation Example
Relative Layout - Views Position in Android
Android Elevation Example


Define Color Value

To define color value, you have to create colors.xml file in your project values directory and add following.
res/values/colors.xml

Create a XML File in Drawable Directory

Create a button_background.xml file in your drawable folder and add button pressed/clicked, focused and default color. Final code of button_background.xml file looks like this.
res/drawable/button_background.xml

Adding Buttons

res/activity_main.xml

Now, run your application and click any of two buttons. You will see different color at the time of click. In following screenshot, first button is at the time of button click/press and another is default.

Change Android Button on Click Color

XML 6039791780382926050
Home item