本文介绍了如何关闭与双击的WebView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我所著一个活动刚与在Android上运行的web视图。
I writed a activity just with a WebView that runs on an Android.
问题是
我想通过双击关闭活动。
I want to close the activity through double-click.
我用GestureDetector.SimpleOnGestureListener派onDoubleTap(android.view.MotionEvent五)
I use "GestureDetector.SimpleOnGestureListener" faction "onDoubleTap(android.view.MotionEvent e)"
但donnot的工作。
but it donnot work .
我该怎么办呢?
推荐答案
这里有一个小东西,我为你所做的(为了提高自己,帮助你BTW :))
试了一下,它的工作pretty好;)
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");
}
}
这篇关于如何关闭与双击的WebView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!