I am porting a web application to android platform.The app will consist of some web content (accessed using WebView) and some offline content. I need to display some amount of text as offline content in the home screen, and I'm kinda confused how to go about it. I have gone through the android documentation of formatting text, but I found it a bit tedious to use when dealing with more than a few lines of text. So I am considering creating some HTML pages and including them in the res folder of my app. And then loading them using WebView. Is it advisable to use such an approach? or is there a better way out?
Well for simple text you can always do following on a TextView:
someTextView.setText(Html.fromHtml(htmlAsAString));
If as you say it is more complicated (with images and/or css etc.) I'd recommend putting the html in the assets/ folder and load it from there directly into a WebView.
There's the Html class which can format HTML text but it's quite limited.
You can read the documentation here:
http://developer.android.com/reference/android/text/Html.html
The method that you'll probably be most interested in is Html.fromHtml(java.lang.String). It returns an Spanned object which you can then use to populate a TextView by simply calling textView.setText(..).
If you find that it does not provide the required support for the HTML tags that you need then you'll most likely end up using a WebView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With