delight-im / Android-AdvancedWebView

Enhanced WebView component for Android that works as intended out of the box
MIT License
2.39k stars 574 forks source link

How to prevent Navigation/Disable links #175

Closed AsfanUlla closed 6 years ago

AsfanUlla commented 6 years ago

How can i disable navigation in the webview

ocram commented 6 years ago

What do you want to achieve exactly?

Just showing a single page where the user can neither navigate forwards nor backwards from?

If so, try overriding shouldOverrideUrlLoading in a custom WebViewClient and always return true from there.

hitesh-shukla commented 6 years ago

shouldOverrideUrlLoading not working

private void loadWebView(AdvancedWebView webView, String htmlString){
        try{
            WebViewClient webViewClient = new WebViewClient(){
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {

                    return true;
                }
            };

            webView.getSettings().setUseWideViewPort(true);
            webView.getSettings().setLoadWithOverviewMode(true);
            webView.getSettings().setSupportZoom(true);
            webView.getSettings().setBuiltInZoomControls(true);
            webView.getSettings().setDisplayZoomControls(false);
            webView.setWebViewClient(webViewClient);
            webView.setDesktopMode(false);
            webView.loadDataWithBaseURL("file:///android_asset/", htmlString, "text/html", "utf-8", "");

        } catch(Exception e){
            e.printStackTrace();
        }
    }
ocram commented 6 years ago

@hitesh-shukla What’s not working exactly? Can you print log statements to see if the shouldOverrideUrlLoading method is actually called? Further, can you replace AdvancedWebView with just WebView everywhere and comment out the non-existing function calls afterwards, reducing this to a minimal example? Does it work then?