是否有可能将 html 从 res/raw 加载到 TextView 中? 我知道我可以使用 WebView,但该死的透明度并不总是有效(并非在所有设备上)
最佳答案
myTextView.setText(Html.fromHtml(readTxt()));
//此函数将返回您可以在 TextView 中设置的字符串。那个字符串有 html 代码,所以使用 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 android - 如何将 html 从资源设置为 TextView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18421553/