问题
I writed a activity just with a WebView that runs on an Android.
The problem is
I want to close the activity through double-click.
I use "GestureDetector.SimpleOnGestureListener" faction "onDoubleTap(android.view.MotionEvent e)"
but it donnot work .
How I can do it??
回答1:
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");
}
}
来源:https://stackoverflow.com/questions/9293873/how-to-close-a-webview-with-double-click