java - Android: Button does not change color when pressed -


i have made custom_button.xml in drawable folder when buttons pressed, , default. looks follows:

<selector xmlns:android="http://schemas.android.com/apk/res/android">  <item android:state_pressed="true" >     <shape>         <gradient             android:startcolor="@color/red"             android:endcolor="@color/light_red"             android:angle="270" />         <corners             android:radius="5dp" />     </shape> </item>  <item>     <shape>         <gradient             android:startcolor="@color/light_purple"             android:endcolor="@color/purple"             android:angle="270" />         <corners             android:radius="5dp" />     </shape> </item> 

my buttons fine when not pressed, shows default purple button. when press it, not change red button should when state_pressed.

in activity_main.xml, buttons defined follows:

<button     android:id="@+id/button1"     android:layout_width="0dp"     android:layout_height="fill_parent"     android:layout_weight="1"     android:background="@drawable/custom_button"     android:layout_margin="5dp"/> 

i'm using nested linearlayout if makes difference.

please let me know if there's i've missed!

edit: found out source of problem, not sure how fix it. when remove these following listeners createlisteners, buttons change color should.

 b1.setontouchlistener(new view.ontouchlistener() {         @override         public boolean ontouch(view v, motionevent event) {             if(event.getaction() == motionevent.action_down) {                 int beat = getbeat(1);                 m1 = mediaplayer.create(mainactivity.this, beat);                 m1.start();                 m1.setlooping(true);                 return true;             } else if (event.getaction() == motionevent.action_up) {                 m1.release();             }             return false;         }     }); 

what it's doing plays song long button pressed. how interfere button color?

it seems ontouchlistener() doesn't work correctly selector. have change background manually in action_down , action_up.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -