1

我有一个 php 文件,其中包含这样的 html 标记

<h4>Standard Web Browser Components</h4>
<p>Let&#8217;s lay out a few components of the modern day web browser:</p>
<ul>
<li>Parsing (HTML, XML, CSS, JavaScript)</li>
<li>Layout</li>
<li>Text and graphics rendering</li>
<li>Image decoding</li>
<li>GPU interaction</li>
<li>Network access</li>
<li>Hardware acceleration</li>
</ul>
<header>
<h1 class="entry-title"><a href="/2012/chrome-canary-for-developers/">Chrome Canary for Developers</a></h1>
<p class="meta">
<time datetime="2012-11-02T08:16:00+04:00" pubdate data-updated="true">Nov 2<span>nd</span>, 2012</time>
</p>
</header>

我想在我的 Android 布局中解析它。我是这样做的

webtext.setText(Html.fromHtml(content));

但我失去了内容的风格和颜色。如何在不丢失样式的情况下在布局中显示。

4

1 回答 1

3

因为只允许以下标签Html.fromHtml()

<a href="...">
<b>
<big>
<blockquote>
<br>
<cite>
<dfn>
<div align="...">
<em>
<font size="..." color="..." face="...">
<h1>
<h2>
<h3>
<h4>
<h5>
<h6>
<i>
<img src="...">
<p>
<small>
<strike>
<strong>
<sub>
<sup>
<tt>
<u>

参考 http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html

PS:

在 WebView 中加载样式等尝试以下

WebView myWebView = (WebView) findViewById(R.id.yourWebViewId);
String strHtml = "<html><head>"
          + "<style type=\"text/css\">body{color: #ffdec2; background-color: #1F0C01;}"
          + "</style></head>"
          + "<body>"
          + "<p align=\"justify\">"                
          ....................
          ....................
          ....................
          + "</p> "
          + "</body></html>";

myWebView.loadData(strHtml, "text/html", "utf-8");
于 2013-07-30T11:01:58.627 回答