[英]How to close a WebView with double-click?
I writed a activity just with a WebView that runs on an Android. 我只使用在Android上运行的WebView编写了一个活动。
The problem is 问题是
I want to close the activity through double-click. 我想通过双击关闭活动。
I use "GestureDetector.SimpleOnGestureListener" faction "onDoubleTap(android.view.MotionEvent e)" 我使用“GestureDetector.SimpleOnGestureListener”派系“onDoubleTap(android.view.MotionEvent e)”
but it donnot work . 但它不起作用。
How I can do it?? 我怎么能这样做?
Here's a little stuff I did for you (in order to improve myself and help you btw :) ) Tried it and it worked pretty well ;) : 这是我为你做的一些小事(为了提高自己,并帮助你顺便:) :)尝试它,它工作得很好;):
package com.spinner.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.webkit.WebView;
public class MyActivity extends Activity {
/** Called when the activity is first created. */
GestureDetector gs = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView wvView = (WebView) findViewById(R.id.webviewid);
wvView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (gs == null) {
gs = new GestureDetector(
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
MyActivity.this.finish();
return true;
}
});
}
gs.onTouchEvent(event);
return false;
}
});
wvView.loadUrl("http://www.google.fr");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.