0

我正在尝试使用以下功能在 WebView 中显示 div

browser.loadData("<html> <head> <body> <H2> HI </H2>  " +
"<div id='map_canvas' style='width:20%;height:20%;'></div>" +
" </body> </head>  </html>", "text/html", "UTF-8");

但这不会加载 html 页面会给出错误

browser.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageFinished(WebView view, String url){
                System.out.println("URL:::"+url);
            }

            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                    System.out.println("URL:::"+failingUrl+" "+description+" "+errorCode);
                    Toast.makeText(getApplicationContext(), "Oh no! " + description, Toast.LENGTH_LONG).show();
            }

        });

显示为您尝试加载的 URL 的响应无效。请告诉我这里有什么问题

4

2 回答 2

1

安卓 2.3

    // display the data

    String baseUrl = "";
    String mimeType = "text/html";
    String encoding = "UTF-8";
    html = sb.toString();
    String historyUrl = "";

    webViewDataViewer.loadDataWithBaseURL(baseUrl, html, mimeType, encoding, historyUrl);
于 2012-12-10T14:39:57.723 回答
0

% 符号不会在 Android 2.2 webview 中加载它必须被编码。

于 2013-03-04T12:57:15.137 回答