Android: how to do background clickable effect by programmatically? -


i have background button.

   <selector xmlns:android="http://schemas.android.com/apk/res/android">     <item android:state_focused="true" android:state_pressed="false" android:drawable="@android:color/transparent" />     <item android:state_focused="true" android:state_pressed="true" android:drawable="@color/whitetransparent50" />     <item android:state_focused="false" android:state_pressed="true" android:drawable="@color/whitetransparent50" />     <item android:drawable="@android:color/transparent" /> </selector> 

but not want. because have 1 main image. , image has 2 section call , b. when press section main image changing c image. , when press b section main image changing d image. solution is:

a.setontouchlistener(new view.ontouchlistener() {             @override             public boolean ontouch(view view, motionevent motionevent) {                 switch (motionevent.getaction()){ //                    action pressed                     case motionevent.action_down:{                         glide.with(getactivity())                                 .load(r.drawable.c_image)                                 .into(iv);                         return true;                     }                     case motionevent.action_up:{                         glide.with(getactivity())                                 .load(r.drawable.main_image)                                 .into(iv);                         return true;                     }                 }                 return false;             }         });          b.setontouchlistener(new view.ontouchlistener() {             @override             public boolean ontouch(view view, motionevent motionevent) {                 switch (motionevent.getaction()){ //                    action pressed                     case motionevent.action_down:{                         glide.with(getactivity())                                 .load(r.drawable.d_image)                                 .into(iv);                         return true;                     }                     case motionevent.action_up:{                         glide.with(getactivity())                                 .load(r.drawable.main_image)                                 .into(iv);                         return true;                     }                 }                 return false;             }         }); 

but when setonclicklistener's not working? thought is: (android:state_focused="false" android:state_pressed="true) it's working.(android:state_focused="true" android:state_pressed="true") it's not working. how it?


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -