Visual effect when clicking the button disappears when I assign a background

Asked

Viewed 555 times

1

I’m trying to make a simple button on an Android app. When inserting the button the effects worked normally, but after performing the background color change, the effect when clicking the button is gone, getting static.

I wonder which property I use to solve 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"
/>

1 answer

1


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

only in your drawable folder right click, go in 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 the effect.

And on your button you say this selector in the backgroud

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

The color codes you get here http://html-color-codes.info/Codigos-de-Cores-HTML/ http://www.ufpa.br/dicas/htm/htm-cor2.htm

  • @Hiago worked

  • Hi Rodolfo! Sorry for the delay. I tried to create the XML file where you told me, but it always creates outside. And the contents of the file should be just the one that sent me? Thanks in advance for the reply!!

  • Rodolfo, I was able to create the file, but when trying to run the application the following error occurs http://pastebin.com/0fhJBzZ

  • add more gave your error code power other thing

  • Activity: http://pastebin.com/NHwsErNv Selector_button: http://pastebin.com/BUUGLDbi Error: http://pastebin.com/0fhJBzZ

  • @Thiago look at the edition and see if it will work

  • Jewel, now it’s working!

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.