显示Div时出现Android WebView错误

时间:2012-12-10 14:36:56

标签: android html webview android-webview

我正在尝试使用以下函数在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();
            }

        });

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

2 个答案:

答案 0 :(得分:1)

Android 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);

答案 1 :(得分:0)

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