Display HTML Table in webview

2019-01-20 10:27发布

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

Give me some example.

3条回答
Bombasti
2楼-- · 2019-01-20 10:56

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.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-01-20 11:06

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);
查看更多
SAY GOODBYE
4楼-- · 2019-01-20 11:17

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");
查看更多
登录 后发表回答