简体   繁体   English

Android WebView loadDataWithBaseURL

[英]Android WebView loadDataWithBaseURL

I have a PHP service that returns me HTML that I display in a WebView using 我有一个PHP服务,返回使用HTML在WebView中显示的HTML

    activity_news_complete_webview.loadDataWithBaseURL("", html, "text/html", "UTF-8", null);

Also implemented the WebViewClient as follows 还实现了如下的WebViewClient

 WebViewClient webViewClient = new WebViewClient() {
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
         super.onPageStarted(view, url, favicon);
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
    }

    @SuppressWarnings("deprecation")
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

    @TargetApi(Build.VERSION_CODES.N)
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        view.loadUrl(request.getUrl().toString());
        return true;
    }

    @Override
    public void onLoadResource(WebView view, String url) {
        super.onLoadResource(view, url);
    }
};

In doing so when i tap on any , the WebViewClient shows that the url attribute is about:blank but the tag contain proper urla in html variable which i load in the WebView. 这样做时,当我点击any时,WebViewClient显示url属性为about:blank,但标记在我加载到WebView的html变量中包含正确的urla。

Any one who can suggest me a proper solution for this would be a great help, I have read many threads on this issue but haven't found any proper solution because anything i try gives the same issue. 任何可以建议我为此提供适当解决方案的人都将为您带来很大的帮助,我已经阅读了许多有关此问题的主题,但没有找到任何适当的解决方案,因为我尝试的任何方法都给出了同样的问题。

You can use this line replace to .loadDataWithBaseURL(); 您可以使用此行替换为.loadDataWithBaseURL();。

activity_news_complete_webview.loadData(html, "text/html; charset=utf-8", "UTF-8"); activity_news_complete_webview.loadData(html,“ text / html; charset = utf-8”,“ UTF-8”);

Its working perfectly for me. 它非常适合我。 try this one. 试试这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM