我正在从网页中检索一些 html 源代码。当我使用 Html.showHtml(htmlSource);
它没有正确显示图表。
这是图表在网络上的样子,没有着色:
Day Date Time Event Location
Fri Sep 27 4:00 PM Practice MSC Yellow
Sun Sep 29 3:00 PM MJBL Game vs Runnin Rebels MSC Yellow
这是图表的 html 和 css:
<table class="gymschedule">
<colgroup>
<col />
<col />
<col />
<col />
<col width="10" /> <!-- small! -->
<col />
<col />
</colgroup>
<thead>
<tr>
<td>
<nobr>Fri</nobr>
</td>
<td>
<nobr>Nov 1</nobr>
</td>
<td>
<nobr>4:00 PM</nobr>
</td>
<td>
Practice </td>
<td>
<nobr>MSC Yellow</nobr>
</td>
</tr>
<tr>
<td>
<nobr>Fri</nobr>
</td>
<td>
<nobr>Nov 8</nobr>
</td>
<td>
<nobr>4:00 PM</nobr>
</td>
<td>
Practice </td>
<td>
<nobr>MSC Yellow</nobr>
</td>
</tr>
</tbody>
</table>
如何在 Android 手机的文本或 ImageView 中正确显示此图?
最佳答案
Android TextView 不支持 <table>
标签及其关联标签。参见 here获取 TextView 支持的 HTML 标签列表。
要显示它,您需要使用 WebView。首先,将 WebView 添加到您的布局中:
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
然后在关联的 Activity 中加载表格 HTML:
String html = "<table> ..... </table>";
WebView webView = (WebView)findViewById(R.id.webView);
webView.loadData(html, "text/html", "utf-8");
关于Android 显示 TextView 图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18944060/