System.out 在 Android 设备中不起作用(不会在设备上向您显示任何内容),如果您有文本视图,您可以MotionEvent.ACTION_DOWN
像已经在做的那样在您的设备上设置文本,并在MotionEvent.ACTION_UP
您设置您的文本文本视图为空。像这样的东西:
public class TestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
final TextView textView = (TextView) findViewById(R.id.textview);
final Button button = (Button) findViewById(R.id.button);
button.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
textView.setText("Button Pressed");
}
if(event.getAction() == MotionEvent.ACTION_UP){
textView.setText(""); //finger was lifted
}
return true;
}
});
}
}