How to close a WebView with double-click?

微笑、不失礼 提交于 2019-12-23 03:26:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!