Try something like this
Button btn = (Button) findViewById(R.id.button);
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] {android.R.attr.state_pressed}, new ColorDrawable(getResources().getColor(R.color.red)));
stateListDrawable.addState(new int[] {-android.R.attr.state_pressed}, new ColorDrawable(getResources().getColor(R.color.green)));
btn.setBackgroundDrawable(stateListDrawable);