Formatting TextView Text Using /strings.xml, HTML, and CSS Values

I am trying to format a TextView with a lot of text to look better, and since I feel it is very easy with HTML and CSS, I thought I would give it away. And since the presence of /strings.xml in the values ​​allows you to localize, I found this to be the best option. Now I am able to get the HTML in the line with:

<![CDATA[ <html code here> ]]> 

But if I try, for example:

 <![CDATA[ <html> <head> <body> <style type=\"text/css\"> p { display: block; border-bottom: 1px solid #31B6E7; } </style> </head> ... etc ]]> 

It just inserts CSS code in plain text, is it impossible to format it with CSS, or does anyone have any good advice for me here?

Thanks for any help on this.

+4
source share
3 answers

You must tell TextView that it is receiving HTML. I think you can find the answer here . This applies to HTML. CSS is not supported - you need to do this using your XML layout ...

+5
source

I think you might expect a little from TextView, or rather, from the Html.fromHtml method, as this turns HTML into Spannable, which you can use with TextView. It is pretty simple. Here is what it supports:

http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html

+6
source

You can use android.webkit.WebView.loadData () to render HTML + CSS instead of TextView.

+1
source

Source: https://habr.com/ru/post/1437703/


All Articles