如何在Android上检测触摸输入 [英] How do I detect touch input on the Android
问题描述
现在我正试图做的是检测屏幕是否被按下,然后显示一条日志消息以确认它发生。到目前为止,我的代码是从CameraPreview示例代码中修改的(它最终将拍摄照片),因此大部分代码都在扩展SurfaceView的类中。来自SDK的示例代码的API为7.
Right now all I am trying to do is detect when the screen is pressed and then display a log message to confirm it happened. My code so far is modified off of the CameraPreview sample code (it will eventually take a picture) so the bulk of the code is in a class that extends SurfaceView. API for the example code from the SDK is 7.
推荐答案
请尝试下面的代码来检测触摸事件。
Try code below to detect touch events.
mView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//show dialog here
return false;
}
});
要显示对话框使用活动方法 showDialog(int)。你必须实现onCreateDialog()。有关详细信息,请参阅文档。
To show dialog use Activity method showDialog(int). You have to implement onCreateDialog(). See documentation for details.
这篇关于如何在Android上检测触摸输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!