Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended approach for presenting formatted text in Android?

I am developing an application that will provide instructions to making a product. The text will have bullets and/or numbered steps as well regular text paragraphs. I may have headings for various sections. The text will be placed into a scrollable TexView.

I was originally planning on loading the text from a resource text file and then applying formatting via xml. However, I just learned about WebView and the ability to load local html files. I could easily format the text in html and load it into a WebView for the various activities.

My question is, is there a performance issue with using WebView vs. TextView? Are there other ways to easily format text for a TextView?

Thanks,

like image 204
chucky Avatar asked Nov 21 '10 01:11

chucky


People also ask

What are the best practices for using text in android?

Using the styles.xml file You may set a style for your TextViews in the styles. xml file and then use that style whenever you require a TextView. As an example, consider the following: XML.

Which component can be used for displaying text in android Apps?

In Android, TextView displays text to the user and optionally allows them to edit it programmatically. TextView is a complete text editor, however basic class is configured to not allow editing but we can edit it. View is the parent class of TextView.


1 Answers

WebView definitely takes longer to load the first time into your process. It also is not designed to go in a ScrollView, since it scrolls itself. OTOH, you get excellent HTML support.

TextView can display limited HTML, converted into a SpannedString via Html.fromHtml(). Here is a blog post where I list the HTML tags supported by the Android 2.1 edition of fromHtml(). Note that these are undocumented, and so the roster of tags may be different in other Android releases.

like image 132
CommonsWare Avatar answered Nov 15 '22 11:11

CommonsWare