I'm creating an Android app, when a user clicks a button in the app the button image should change "to show it has been pressed" then some function is being called
using the following code at the onclick function:
{
btn.setBackgroundDrawable(getResources().getDrawable(R.drawable.sync_active));
sync();
}
what happens is the sync function is called first then the button image changes !!
create xml file using the button image like this with mybutton.xml in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/greencolorbutton" />
<item
android:drawable="@drawable/closebutton" />
</selector>
and use this in button xml code
android:background:@drawable/mybutton
you can check it from this https://stackoverflow.com/q/8132500/964741
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With