ImageButton touch feedback -


how can implement touch feedback imagebuttons? want image button change image when button touched. searched, after trying things didn't worked i'm bit desperate. selector right thing problem , how work?

my current try create new .xml file in drawable folder. there put selector, current code .xml file:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"android:exitfadeduration="@android:integer/config_mediumanimtime"> <item     android:state_pressed="true"     android:drawable="@drawable/testbuttonimageselected" /> <item     android:drawable="@drawable/testbuttonimage" /> </selector> 

and current code .java file:

btntest = (imagebutton) findviewbyid(r.id.btntest); btntest.setonclicklistener(new view.onclicklistener() {      public void onclick(view button) {        //set button's appearance        button.setselected(!button.isselected());          if (button.isselected()) {            //handle selected state change         } else {            //handle de-select state change         }     } }); 

you can using state list, , assigning different image each state: https://developer.android.com/guide/topics/resources/drawable-resource.html#statelist


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -