abstract class KeyButton extends Button implements OnTouchListener {
private String buttontext;
public KeyButton(Context context, String text) {
super(context);
this.setText(text);
this.setBackgroundColor(Color.WHITE); // 设置键的背景色为白色
this.setLayoutParams(new LayoutParams(56, 50));
this.setPadding(0, 0, this.getRight(), this.getBottom()); // 设置填充
this.buttontext = text;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
Button b = (Button) v;
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
this.setBackgroundColor(Color.GRAY);
Log.i("sss", buttontext + "    ACTION_DOWN" + event.getY());
// 向外输出
break;
case MotionEvent.ACTION_UP: if (b.getText().equals(buttontext)) {
this.setBackgroundColor(Color.WHITE);
Log.i("sss",
buttontext + "    ACTION_UP" + event.getPointerCount());
// 向外输出
}
break;
}
return true;
}
}当同时有两个按钮按下的时候,我只释放了第二个按钮,但是日志显示 第一个按钮也action_up了actionup多点触摸