简体   繁体   English

在webview中显示HTML表格

[英]Display HTML Table in webview

How to display HTML table with rows and columns in WebView in Android. 如何在Android中的WebView中显示包含行和列的HTML表。

Give me some example. 给我一些例子。

Create an HTML template 创建一个HTML模板

    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 并加载到您的WebView

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

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

I think that this is an issue related to Android web view's in 2.2 and 2.3. 我认为这是与2.2和2.3中的Android Web视图相关的问题。 The table tags like width, cell-spacing, and cell-padding are not supported in some web views and thus should not be used. 某些Web视图不支持宽带,单元格间距和单元格填充等表格标记,因此不应使用。 If you want to style a table with webView.loadData(), use inline stlying with the style tag only. 如果要使用webView.loadData()设置表的样式,请仅使用样式标记内联。

Table border should also be removed as well. 表格边框也应该被删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM