问题
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