java的机器人 - 如何设置HTML从资源的开发到TextView的? [英] java android - how to set html from resourses to TextView?
本文介绍了java的机器人 - 如何设置HTML从资源的开发到TextView的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能加载从RES HTML /生到TextView的?
我知道我可以使用的WebView,但该死的透明度并不总是工作(不是每个设备上)
解决方案
myTextView.setText(Html.fromHtml(readTxt()));
//这个函数会返回字符串,你可以在你的TextView设置。而该字符串有HTML codeS所以使用 Html.fromHtml
私人字符串readTxt(){
为InputStream的InputStream = getResources()openRawResource(R.raw.My_html_file)。
ByteArrayOutputStream byteArrayOutputStream =新ByteArrayOutputStream();
INT I;
尝试{
I = inputStream.read();
而(ⅰ!= -1)
{
byteArrayOutputStream.write(ⅰ);
I = inputStream.read();
}
inputStream.close();
}赶上(IOException异常五){
// TODO自动生成catch块
e.printStackTrace();
}
返回byteArrayOutputStream.toString();
}
}
Is there any possibility to load html from res/raw into the TextView? I know I can use WebView, but damn transparency is not always working (not on every device)
解决方案
myTextView.setText(Html.fromHtml(readTxt()));
//This function will return string which you can set in your textview. And that String have html codes so use Html.fromHtml
private String readTxt(){
InputStream inputStream = getResources().openRawResource(R.raw.My_html_file);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i;
try {
i = inputStream.read();
while (i != -1)
{
byteArrayOutputStream.write(i);
i = inputStream.read();
}
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return byteArrayOutputStream.toString();
}
}
这篇关于java的机器人 - 如何设置HTML从资源的开发到TextView的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文