--ADVERTISEMENT--

Android button can be used for different purposes and it has different functions and it is one of the important UI components in android. We can customize android button according to our needs and requirement. In this tutorial, you will learn to make android button selector. Android button selector means adding some effect to the button when user clicks or touches the button.

We can use image as button background when the button is clicked/selected/pressed. Here I have added new color value which is visible while pressing the button.

This is very simple task, for this we have to create an XML file in drawable folder and adding some XML code.

Related:
How to Implement Ripple Effect in Android
How to Add Ripple Effect/Animation to a Android Button
How to Make Android TextView Text Selectable

Android Example: How to Make Button Selector in Android


Let’s start by creating new XML file called button_selector_effect.xml in res/drawable folder. Following is the complete content of drawable XML file.

res/drawable/ button_selector_effect.xml

Colors.xml File

Following are the different color values of colors.xml file.

XML Layout File

Here I have added one button with background attribute and used background as above XML drawable file that we have created before. Following is the complete content of XML layout file.

res/layout/ button_selector_android_example.xml

Java Activity File

Default code of java activity file will look like below.

src/ AndroidButtonSelectorExample.java

Strings.xml File

Android Example: How to Make Button Selector in Android

Now, run your Android Button Selector Example application and click the button, you will see different color when you press/click the button then default color which will look like above screenshot.

Post a Comment

Powered by Blogger.