Reputation: 811
I have value on string:
String htmlValue = "<div style="text-align: center;"><span style="font-family: impact, chicago; font-size: 18px;">Exchange Offer !! </span></div>
<div style="text-align: center;"><span style="font-size: 14px;">any mobile phone</span> , <span style="font-size: 14px;">give your</span> <span style="font-family: impact, chicago; font-size: 20px;">take new one</span>.</div>";
and how to display such type div included in textview.
I have try this but only content display div styling could not display.
Spanned result= Html.fromHtml(htmlValue);
tvFooter.setText(result);
or
tvFooter.setText(Html.fromHtml(htmlValue));
Here Defined: http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html , div supported but could get exact expected output by doing above. I have both of above trick, but not working.
Error Output:
Expected Output like this
:
Upvotes: 1
Views: 4301
Reputation: 580
As I scanned the source code of /frameworks/base/core/java/android/text/Html.java , the attribute style
and the tag span
are not supported. Suggest using webview instead of textview
Following tags or attributes seems to be supported in Lollipop,
- <br>
- <p>
- <div>
- <strong>
- <b>
- <em>
- <cite>
- <dfn>
- <i>
- <big>
- <small>
- <font color="..." face="...">
- <blockquote>
- <tt>
- <monospace>
- <a href="...">
- <u>
- <sup>
- <sub>
- <h1>
- <h2>
- <h3>
- <h4>
- <h5>
- <h6>
- <img src="...">
Upvotes: 2
Reputation: 1340
All html tags are not supported by Html.fromHtml() check here the supported tags in textview.So better you use webview instead of textview to load the html content. like
yourwebview.loadData(yourhtmlData, "text/html", "UTF-8");
Upvotes: 0