如何按下按钮变为绿色,按键再次变为红色。
答案 0 :(得分:1)
@Override
public boolean onTouch(final View view, MotionEvent event) {
final int action = event.getAction();
if(view.getId()==R.id.yourButton){
if(action == MotionEvent.ACTION_DOWN)
yourButton.setBackgroundResource(R.drawable.ic_button_green);
if(action == MotionEvent.ACTION_UP)
yourButton.setBackgroundResource(R.drawable.ic_button_red);
}
}