Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display HTML content without webview in android

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.

like image 288
andro-girl Avatar asked Sep 13 '25 23:09

andro-girl


1 Answers

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

like image 105
Julian Goacher Avatar answered Sep 15 '25 12:09

Julian Goacher