1

I have such String:

<p><span style="color: rgb(230, 0, 0);">should be text color red</span></p><p><br></p><p><br></p><p><span style="background-color: rgb(230, 0, 0);">should be text color red background</span></p>

Is there a way to display it in TextView?

I wanted to do this like that: contentTextView.setText(Html.fromHtml(presentation.content),TextView.BufferType.SPANNABLE)

Or is there any library for overcoming my issue?

K.Os
  • 5,123
  • 8
  • 40
  • 95
  • If fromHtml isn't doing it, you'd have to write your own parser and create the appropriate Spannables. Possibly up to and including creating custom Spannables. Using HTML for text is really not something heavily encouraged in Android. – Gabe Sechan Mar 16 '18 at 14:02
  • @GabeSechan yep, but i really need to use HTML because of retrieving it same as in the backend HTML editor which i need to display also in the Android app, same formatted as there – K.Os Mar 16 '18 at 14:04
  • 1
    Then you may want to use a webview, if you're displaying HTML content. But that's pretty much your options: fromHtml, a webview, or doing all your own HTML parsing to create Spannables (or finding a library that does it). – Gabe Sechan Mar 16 '18 at 14:07
  • Can you see this https://stackoverflow.com/questions/49323455/java-lang-illegalargumentexception-parameter-specified-as-non-null-is-null-for Is there possibility that the content is loading that fast that the progressBar is not appeariing at all? However I need this(there is like 1 second loading) – K.Os Mar 16 '18 at 14:59
  • https://github.com/Pixplicity/HtmlCompat – Jude Fernandes Mar 16 '18 at 18:25
  • @JudeFernandes thanks, but this library is not supporting my case i think, you can check – K.Os Mar 17 '18 at 11:25
  • Have you tried any other library, there are quite a few out there, https://github.com/PrivacyApps/html-textview is a good one too , or if you know the text is always going to be as above then you could write your own parser to pick up the styles and then apply them. – Jude Fernandes Mar 17 '18 at 13:22
  • @K.Os I m also facing the same issue you find any solution? – Vanraj Ghed Feb 07 '20 at 06:50
  • @VanrajGhed there are some libraries that can partially help you with that, but if you must handle plenty of different HTML/CSS styling you can just go with WebView (I was forced to do that anyway) – K.Os Feb 08 '20 at 17:58

0 Answers0