在API 18中使用什么代替getUrl()

时间:2017-12-30 14:00:20

标签: android webview

我使用API​​级别18表单显示同一活动中的网页,但它会显示错误:getURL() required API 21。 我可以用什么代替呢?

以下是代码:

 @Override
        public boolean shouldOverrideUrlLoading(WebView view, 
 WebResourceRequest request) {
            view.loadUrl(request.getUrl().toString());
            return false;
        }

1 个答案:

答案 0 :(得分:0)

尝试一下

private void LoadUrlWebView( String url_api ) {
    try {
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setSupportZoom(true);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDisplayZoomControls(false);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        webView.getSettings().setAllowContentAccess(true);
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                //public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                Log.i( "","setWebViewClient::shouldOverrideUrlLoading::url: "+url);
                webView.loadUrl(url);
                CookieManager.getInstance().setAcceptCookie(true);
                return true;
                //return super.shouldOverrideUrlLoading(view, request);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                Log.i( "setWebViewClient::onPageFinished::url: ", url);
            }
        });
        webView.setWebChromeClient(new WebChromeClient(){
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                try {
                    progressBar.setProgress(newProgress);
                    if ( newProgress < 100 && progressBar.getVisibility()==ProgressBar.GONE) {
                        progressBar.setVisibility(ProgressBar.VISIBLE);
                    }
                    if (newProgress == 100) {
                        progressBar.setVisibility(ProgressBar.GONE);
                    }
                }catch (Exception e){
                    Log.i( "onProgressChanged", e);
                }
            }

            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                setTitle( title );
                Tools.LogCat("setWebChromeClient::onReceivedTitle:: getUrl:"+ view.getUrl() + "\ntitle:"+title );
            }
        });

        webView.loadUrl(view.getUrl());
    } catch (Exception e) {
        Tools.LogCat(this, "setUpNavigationView", e);
    }
}