당신이 내 확장 버튼 클래스를 할 수 있습니다 코드 onTouchEvent. 제 예제에서는 배경과 텍스트 색상을 변경하면서 배경 이미지에 색조 (컬러 필터)를 사용하여 이미지 색상을 변경할 수 있습니다.
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);
}
}
도움이 될 경우 대답을 수락하십시오. !!! – W4R10CK