android - Why text is not formatted with Html.fromHTML? -
i'm trying display html code in text view. want display this:
i'm using page generate code: http://tohtml.com/java/
html:
<pre style='color:#000000;background:#ffffff;'><span style='color:#7f0055; font-weight:bold; '>public</span> <span style='color:#7f0055; font-weight:bold; '>class</span> mainactivity <span style='color:#7f0055; font-weight:bold; '>extends</span> activity { <span style='color:#3f7f59; '>// called when activity created</span> @override <span style='color:#7f0055; font-weight:bold; '>protected</span> <span style='color:#7f0055; font-weight:bold; '>void</span> oncreate(bundle savedinstancestate) { <span style='color:#7f0055; font-weight:bold; '>super</span>.oncreate(savedinstancestate); setcontentview(r.layout.main); } } </pre>
i'm tried this:
textview textview; // text view string data = loaddataasstring("/sdcard/code.html"); // function loads data file , returning string. textview.settext(html.fromhtml(data), textview.buffertype.spannable);
and i'm getting result:
how can fix it?
i don't want use webview.
i'm using api 19 (android 4.4.4 - kitkat)
html.fromhtml()
supports subset of html tags. this list bit out of date, give idea of can , cannot use. need alter html abide html elements fromhtml()
can work with.
alternatively:
use
webview
instead oftextview
, oruse different html->
spanned
parser, myspannablestringgenerator
, if works html more liking
Comments
Post a Comment