Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rich text in a textview

Tags:

I need to create an "Info" for my program. I'd like to fill the info text with several colors, style, fonts, etc.

I found this link with a way how to achieve it.

Is there any other way (better or easier) to do this?

like image 324
Pol Hallen Avatar asked Nov 12 '12 19:11

Pol Hallen


People also ask

How do I display rich text?

Right-click the rich text box for which you want to enable or disable full rich-text formatting, and then click Rich Text Box Properties on the shortcut menu. Click the Display tab. To enable full rich-text formatting for the selected rich text box, select the Full rich text (images, tables, etc.)

What is rich text in Android?

Rich texts format are texts that you can edit and transform the text font. It is possible to put it in bold, italic, underline, copy and paste text format over another, use caps lock and other functions.

What is the difference between text and rich text?

When you want to create a document, two important formats to consider are rich text and plain text. Rich text allows you to include a variety of visual features, while plain text keeps your document stylistically simple and offers few customization options.

What is rich text content?

What is rich text? Rich text is text that is formatted with common formatting options, such as bold and italics, that are unavailable with plain text. You format your data by using common formatting tools, such as the Ribbon and the Mini Toolbar.


1 Answers

Upon reading your question title, I was prepared to give you a link to that exact article. I've found using spans and SpannableString to be quite powerful. The alternate would be to use HTML formatting for your text, which can be done with Html.fromHtml().

However, It's not exactly clear which HTML tags are supported, since the documentation simply reads:

This class processes HTML strings into displayable styled text. Not all HTML tags are supported.

So, for a good solution, I would definitely go with the SpannableString approach in the article. This method is very handy in practice since you can also make your own span classes that extend the existing ones (for example, if you want to have a section of text use a custom font that isn't built in).

like image 96
wsanville Avatar answered Sep 23 '22 08:09

wsanville