1

I have value on string:

String htmlValue = "<div style="text-align: center;"><span style="font-family: impact, chicago; font-size: 18px;">Exchange Offer !!&nbsp;</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:

enter image description here

Expected Output like this

:enter image description here

Bixms
  • 771
  • 1
  • 7
  • 16
  • htmlValue you have used must be string,check that if it is string,like "
    ..."
    – Jemshit Apr 08 '15 at 10:48
  • show code of where you set htmlValue – Jemshit Apr 08 '15 at 10:50
  • I got this string value from server, and just want to display on **textview**. what i try , i gave above sample. – Bixms Apr 08 '15 at 10:51
  • but inside you have nested "", try putting \ before all " inside string – Jemshit Apr 08 '15 at 10:52
  • The " problem would cause a compile error. So that is unlikely to be the actual issue. @Bixms: The image, is that the expected output or the actual output. If it is not the actual output, please add an image of the actual output. – Knossos Apr 08 '15 at 10:53
  • I don't immediately see why you are facing issues. However, there are different methods you can use as reported here: http://stackoverflow.com/a/29004794/503508 – Knossos Apr 08 '15 at 10:59
  • @Knossos it does not even compile with multiple " – Jemshit Apr 08 '15 at 11:03
  • 1
    @Bixms it appears to be "style" tag is not supported : http://daniel-codes.blogspot.com.tr/2011/04/html-in-textviews.html – Jemshit Apr 08 '15 at 11:09
  • Are you sure that you have to use TextView? You can play with WebView. – vdmytsyk Apr 08 '15 at 11:12

3 Answers3

2

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="...">
yummy
  • 570
  • 3
  • 9
1

You need to write \ before inside " because they're closing your string before they properly end, like Jemshit Iskenderov says.

Also, the tags style and span can't be shown in a textview. Check this link for a list of HTML tags that work in textview.

Revi
  • 9
  • 2
0

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");
Chandra Sharma
  • 1,339
  • 1
  • 12
  • 26