【问题标题】:How to close a WebView with double-click?如何通过双击关闭 WebView?
【发布时间】:2012-02-15 21:47:05
【问题描述】:

我只使用在 Android 上运行的 WebView 编写了一个活动。

问题是

我想通过双击关闭活动。

我使用“GestureDetector.SimpleOnGestureListener”派系“onDoubleTap(android.view.MotionEvent e)”

但它不起作用。

我该怎么做??

【问题讨论】:

    标签: android webview double-click


    【解决方案1】:

    这是我为你做的一些事情(为了提高自己并帮助你顺便说一句:)) 试过了,效果很好;) :

    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");
    
        }
    }
    

    【讨论】:

    • 谢谢!但是如果我 loadurl "file:///android_asset/first.html" webview 不能滚动,我不知道为什么。
    • “WebView 不能滚动”,我不太明白你的意思?!无论如何,如果对你有帮助,请标记我的回答!谢谢
    • 但是如果我加载url "file:///android_asset/first.html",当我点击网页时webview没有响应。
    • 可能和你的 first.html 有关,如果里面有一些 javascript 或 W/E...
    • 我发现“first.html”有问题,现在可以使用了!谢谢!
    猜你喜欢
    • 2012-12-14
    • 2017-10-20
    • 2012-02-04
    • 1970-01-01
    • 2011-08-21
    • 2011-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多