In Android, Display pressed button animation in OnClick?

Kasius

New Member
I haven't found a straight answer to how to make an animation in a button when onClick is called. I've got a custom_btn.xml like so:\[code\] <?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/btn_pressed"></item> <item android:state_focused="true" android:drawable="@drawable/btn_on"></item> <item android:drawable="@drawable/btn"></item></selector>\[/code\]and the animation is in btn_pressed.xml like so:\[code\] <?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/btn_on_1" android:duration="30" /> <item android:drawable="@drawable/btn_on_2" android:duration="30" /> <item android:drawable="@drawable/btn_on_3" android:duration="30" /> <item android:drawable="@drawable/btn_on_4" android:duration="30" /> <item android:drawable="@drawable/btn_on_5" android:duration="30" /></animation-list>\[/code\]my problem is that I can't seem to find the right code to go in the onClickListener here:\[code\] button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //-- what is the proper animation call that would go here to make btn_pressed.xml cycle only once when pressed? } });\[/code\]thanks!
 
Back
Top