Android 按下并释放图像时更改图像按钮图像

Android 按下并释放图像时更改图像按钮图像,android,android-layout,Android,Android Layout,我有一个按钮。我希望当我点击它的时候图像会改变。我试图在onCLick方法中调用setBackground,但它不接受R.drawable。请问我应该用什么。使用 button.setImageResource(resId) 例如: public boolean onTouch(View v, MotionEvent me) { int action = me.getAction(); if(action == MotionEvent.ACTION_DOWN) {

我有一个按钮。我希望当我点击它的时候图像会改变。我试图在onCLick方法中调用setBackground,但它不接受R.drawable。请问我应该用什么。

使用

button.setImageResource(resId)
例如:

public boolean onTouch(View v, MotionEvent me) {
    int action = me.getAction();
    if(action == MotionEvent.ACTION_DOWN) {
        button.setImageResource(R.id.resId1)
        //other stuff
        return true;
    } else if (action == MotionEvent.ACTION_UP) {
        button.setImageResource(R.id.resId2)
        //other stuff
        return true;

    }
    return false;
}

创建可绘制的状态列表:它们允许您为各种按钮状态定义不同的可绘制