Reputation:
I'm trying to change the background of a button as a "loading" while it's pressed, but I'm not sure how to make.
First I tried to use a progress bar but, what I want is to load the background progressively if the button is pressed or revert it if the button is released.
Thanks in advance for any idea.
Upvotes: 0
Views: 146
Reputation: 3608
Set the button background to a selector, such as this
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/loading" android:state_pressed="true" />
<!-- pressed -->
<item android:drawable="@drawable/normal" android:state_focused="true" />
<!-- focused -->
<item android:drawable="@drawable/normal" />
<!-- default -->
</selector>
That should change the button background as you press and release the button.
Upvotes: 1