0

I want to set a different background color for a button only while the button is being touched by the user.

But that color remains that way during the whole time onClick for that button is running even though I am no longer touching the button

Please help me find a solution to this

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="#777777" />
    <item android:color="@android:color/black" />
</selector>
Mitul Agrawal
  • 105
  • 1
  • 7

1 Answers1

0

Assuming your on-click method takes a long time, You should add a second item for stating the case of the button not being pressed:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="#777777" />
    <item android:state_pressed="false" android:color="#000000"/>
    <item android:color="@android:color/black" />
</selector>