2016-11-13 67 views
0

這顯示HTML文件上TextView的內容(帶格式)的HTML文件我想顯示在TextView的:我想在安卓

<html> 
<head> 
    <link rel="stylesheet" href="highlight/styles/default.css"> 
    <script src="highlight/highlight.pack.js"></script> 
    <script>hljs.initHighlightingOnLoad();</script> 
</head> 
<body> 

<h1>C Program to Calculate Area of Circle</h1> 
<p class="test"><pre><code class="c">#include&lt;stdio.h&gt; 

int main() { 
    area = 3.14 * radius * radius; 
    printf("\nArea of Circle : %f", area); 
} 
</code></pre></p> 
<br> 
<!--Output--> 
<div><br>Enter the radius of Circle : 2.0<br> 
Area of Circle : 6.14<br>&nbsp;</div> 
</body> 
</html> 

它具有外部鏈接到一些的.js.css文件

我已將它存儲在資產文件夾中。

htmlContentInStringFormat=""; 
String htmlFilename = "www/"+fileName; 
AssetManager mgr = getBaseContext().getAssets(); 
InputStream in = mgr.open(htmlFilename, AssetManager.ACCESS_BUFFER); 
htmlContentInStringFormat = StreamToString(in); 
in.close(); 

我使用mTextview.setText(Html.fromHtml(htmlContentInStringFormat)),但它顯示的是純文本。我想正確的個性化文字,因爲它是顯示當我打開的.html文件像這樣:

desired output

請幫助我。

+0

使用webview的。 –

+0

目前我只使用WebView,但在某些設備上加載似乎很慢。這就是爲什麼我想在TextView上顯示它。 –

回答

0

Html.fromHtml()將讓你在TextView查看重量輕HTML

myTextView.setText(Html.fromHtml(htmlContentInStringFormat)); 

如果你希望你的JS和CSS與它的工作,你將需要使用WebView。要從資產中加載HTML文件到WebView,您可以refer this answer here

+0

我只使用它,但我沒有得到所需的輸出。請看看我發佈的問題的圖像,這就是我希望文本出現在TextView上的方式,但它並沒有鏈接用於樣式化我的html的外部.js和.css文件。 –

+0

如果你想要外部的JS和CSS來處理它,你需要在'WebView'中加載它。 'TextView'不能處理完整的網頁。 –

+0

查看我編輯的答案以獲取更多詳細信息。 –