Display HTML Table in webview

淺唱寂寞╮ 提交于 2019-12-17 20:48:27

问题


How to display HTML table with rows and columns in WebView in Android.

Give me some example.


回答1:


Create an HTML template

    String myTable = "<table border=1>" +
        "<tr>" +
        "<td>row 1, cell 1</td>" +
        "<td>row 1, cell 2</td>" +
        "</tr>" +
        "<tr>" +
        "<td>row 2, cell 1</td>" +
        "<td>row 2, cell 2</td>" +
        "</tr>" +
        "</table>";

and load into your WebView

myWebView.loadDataWithBaseURL(null, myTable, "text/html", "utf-8", null);



回答2:


Its also working for me:

String tag = "<table border=1>" +
                "<tr>" +
                   "<td>row 1, cell 1</td>" +
                   "<td>row 1, cell 2</td>" +
                "</tr>" +
                "<tr>" +
                   "<td>row 2, cell 1</td>" +
                   "<td>row 2, cell 2</td>" +
                "</tr>" +
             "</table>";

((WebView) findViewById(R.id.web)).loadData(tag, "text/html", "utf-8");



回答3:


I think that this is an issue related to Android web view's in 2.2 and 2.3. The table tags like width, cell-spacing, and cell-padding are not supported in some web views and thus should not be used. If you want to style a table with webView.loadData(), use inline stlying with the style tag only.

Table border should also be removed as well.



来源:https://stackoverflow.com/questions/3525649/display-html-table-in-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!