Webview shouldOverrideUrlLoading not getting called

前端 未结 4 1958
难免孤独
难免孤独 2021-01-02 15:30

I am making an ebook reader which uses epub format to load books into webviews. In some of the books there is an anchor link to some portions in the same chapter. Each chapt

4条回答
  •  鱼传尺愫
    2021-01-02 15:59

    I am not sure whether the below will resolve your problem or not.

    Please add below code before setting the WebViewClient

    reader.getSettings().setLoadWithOverviewMode(true);
    reader.getSettings().setUseWideViewPort(true);
    
    /*This makes the layout/page rendering independent of the devices. 
    I use this to display local HTML pages.*/
    reader.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL); 
    

    In addition I have zoom controls enabled. Please note that I have tested my code from API-10 onwards with multiple devices and brands (HTC, Samsung, Nexus etc.) and found that the shouldOverrideUrlLoading works all the time.

    If things do not work well, try extending the WebViewClient and Override the shouldOverrideUrlLoading method

    class MyWebView extends WebViewClient{
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return false; //THis should be false always
        }
    }
    

    Now set the WebViewClient as reader.setWebViewClient(new MyWebView());

提交回复
热议问题