I want to display HTML content in my app without using webview
. HTML data may contain the text (including style), image, table, etc. Is there any library for this? I have read about HTML parser but if I use this I will have to create each view dynamically. Instead of that is there any other solution? Need help on this.
For HTML with images and basic text formatting you can use Html.fromHtml()
(API doc) and display the result in a TextView
instance.
To display images, you will have to implement the Html.ImageGetter interface, to load image references and convert them to Drawable
.
Tables are trickier. You can implement the Html.TagHandler interface to detect table related tags and decide how to display them, but proper layout of table data can get quite complicated very easily. If your HTML tables are relatively simple - columns and rows with small values, but no cells spanning multiple columns or rows - then it might be feasible to implement a tag handler that collates the table data and displays it in basic columns.
Alternatively, it might be simpler to use something like this https://github.com/SufficientlySecure/html-textview
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