Visual effect when clicking the add button when assigning a background

1

I'm trying to make a simple button in an Android application. When you insert the button the effects worked normally, but after changing the background color, the effect of clicking the button disappeared, becoming static.

I would like to know which property I use to resolve this.

My button is implemented as follows:

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="TEST"
    android:background="#2780E3"
    android:textColor="@android:color/white"
/>
    
asked by anonymous 23.06.2015 / 00:05

1 answer

1

In this case you need to create a selector for your button, a new style, for example.

just in your drawable folder right click, go to new select xml the name you choose in this case selector_button.xml

/res/drawable/selector_button.xml

.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">


    <item android:drawable="@android:color/holo_blue_bright" android:state_selected="true"></item>
    <item android:drawable="@android:color/holo_blue_dark" android:state_pressed="true"></item>
    <item android:drawable="@android:color/holo_blue_light"></item>


</selector>

Remember to put different colors to give effect.

And on your button you inform this selector on backgroud

<Button
            android:id="@+id/btn1"
            android:background="@drawable/selector_button"
/>

The color codes you get here link link

    
23.06.2015 / 00:41