我正在尝试在文本视图中显示html代码。我想显示这个:
我正在使用此页面生成此代码: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 is 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>
我试过这个:
TextView textView; // my text view
String data = loadDataAsString("/sdcard/code.html"); // my function which loads data from file and returning it as String.
textView.setText(Html.fromHTML(data), TextView.BufferType.SPANNABLE);
我得到了这个结果:
我该如何解决?
我不想使用WebView。
我正在使用API 19(Android 4.4.4 - KitKat)