I have a spannable string containing bold italics and underlined text ( it may contain more formatted text ) For Example : - abcdef dfdfdfdf dfgdfgfdgf dfgfdgdfgfdfgd
I want to convert this string into html formatted text such that, my final output contains tags such that the above string should become
abcdef dfdfdfdf dfgdfgfdgf dfgfdgdfgfdfgd
TextUtils.htmlEncode
is not working. Real World Scenario - You view a webpage and when you view its source it contains tags. Similar thing i want here
this is how to convert string to html but consider not all html tags working on android .
Spanned htmlText = Html.fromHtml(text);
mytextView.setText(htmlText);
android supported only this html tags
<a href="...">
<b>
<big>
<blockquote>
<br>
<cite>
<dfn>
<div align="...">
<em>
<font size="..." color="..." face="...">
<h1>
<h2>
<h3>
<h4>
<h5>
<h6>
<i>
<img src="...">
<p>
<small>
<strike>
<strong>
<sub>
<sup>
<tt>
<u>
You need to use Html.toHtml()
to convert your Spanned
text into HTML string.
String htmlString = Html.toHtml(spannedText);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With