Android WebView:删除google drive/doc viewer中的弹出选项

Abh*_*k V 15 pdf android google-docs android-webview google-drive-api

我通过将pdf url附加到google doc api来加载WebView中的pdf文档

http://docs.google.com/gview?embedded=true&url=myurl

Pdf加载得很好,但网页显示两个选项 - Zoom-inPop-Out.有没有办法通过发送一些参数来禁用/隐藏弹出选项?任何帮助将不胜感激.谢谢!

在此输入图像描述

小智 10

您可以添加此回调,结果"弹出"按钮将被删除.

@Override
    public void onPageFinished(WebView view, String url) {

        super.onPageFinished(view, url);
        mWebView.loadUrl("javascript:(function() { " +
                "document.querySelector('[role=\"toolbar\"]').remove();})()");
    }
Run Code Online (Sandbox Code Playgroud)

注意:如果您现在想要显示此按钮,请在应用上一个javascript代码后显示您的Web视图.

  • 我发现你的解决方案对于已接受的答案很有用,但是你注意到当进度条运行时,它仍然显示弹出选项,所以任何人都可以点击它...并执行进一步的操作.你有任何解决方案吗? (2认同)

jaf*_*far 5

//initialze WebView
webview = (WebView) findViewById(R.id.fullscree_webview);

//set the javascript enable to your webview
webview.getSettings().setJavaScriptEnabled(true);

//set the WebViewClient
webview.setWebViewClient(new WebViewClient() {

//once the page is loaded get the html element by class or id and through javascript hide it.
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            webview.loadUrl("javascript:(function() { " +
                    "document.getElementsByClassName('ndfHFb-c4YZDc-GSQQnc-LgbsSe ndfHFb-c4YZDc-to915-LgbsSe VIpgJd-TzA9Ye-eEGnhe ndfHFb-c4YZDc-LgbsSe')[0].style.display='none'; })()");
        }
    })
Run Code Online (Sandbox Code Playgroud)