如何检测 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;
}
});
要显示对话框使用 Activity 方法 showDialog(int).您必须实现 onCreateDialog().详情请参阅文档.
To show dialog use Activity method showDialog(int). You have to implement onCreateDialog(). See documentation for details.
这篇关于如何检测 Android 上的触摸输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!