1

This is the HTML file I want to display on the 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> 

It has external linking to some .js and .css files

I've stored it in assets folder.

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

I'm using mTextview.setText(Html.fromHtml(htmlContentInStringFormat)), but it is displaying plain text. I want proper stylized text, as it is displayed when I open the .html file like this :

desired output

Please help me.

Shyam Zawar
  • 25
  • 2
  • 11

1 Answers1

2

Html.fromHtml() will let you view light weight HTML in a TextView:

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

If you want your JS and CSS to work with it, you will need to use a WebView. To load an HTML file from your assets into a WebView you may refer this answer here.

Community
  • 1
  • 1
Kamran Ahmed
  • 7,661
  • 4
  • 30
  • 55
  • I'm using that only, but I'm not getting the desired output. Please have a look at the image I posted with question, that's how i want the text to appear on the TextView, but It is not linking the external .js and .css files I used for styling my html. – Shyam Zawar Nov 13 '16 at 04:21
  • If you want external JS and CSS to work with it, you will need to load it up in a `WebView`. `TextView` is not made to handle a full fledged web page. – Kamran Ahmed Nov 13 '16 at 04:23