You can do this my extending Button class with your code in onTouchEvent. In my example i am changing background and text color you can change image color by using Tint(color filter) on background image.
public class MyButton extends Button {
public MyButton(Context context) {
super(context);
}
public MyButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public MyButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void setEnabled(boolean enabled) {
// super.setEnabled(enabled);
if (!enabled)
setBackgroundColor(Color.GRAY);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
//when Button is Pressed
if (!isPressed()) {
setBackgroundColor(YOUR PRESSED COLOR);
setTextColor(Color.BLACK);
}else {//when Button Released
setBackgroundColor(<YOUR INACTIVE COLOR>);
setTextColor(Color.BLACK);
}
return super.onTouchEvent(event);
}
}