Q:

Android: Button does not change color when pressed

I have made a custom_button.xml in my drawable folder for when my buttons are pressed, and for default. It looks as 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 look fine when not pressed, it shows the default purple button. But when I press it, it does not change to the red button as it should be when state_pressed. 
In my activity_main.xml, the buttons are defined as 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 that makes any difference.
Please let me know if there's something I've missed!
EDIT: I found out the source of the problem, but not sure how to fix it. When I remove these following listeners from my createListeners, the buttons change color as they 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 basically doing is that it plays a song for as long as the button is pressed. How does this interfere with the button color?

A:

It seems that onTouchListener() doesn't work correctly with selector. You have to change background manually in ACTION_DOWN and ACTION_UP.

