java android - 如何将 html 从资源设置为 TextView?

标签 java android html textview

是否有可能将 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/

相关文章:

android - 如何让我的浏览器从右向左滑动

JavaScript localStorage 返回 1?

java - 无法使用 org.eclipse.paho.client.mqttv3 连接到 Azure IOT MQTT

java - 为什么 "while (i++ < n) {}"明显比 "while (++i < n) {}"慢

java - 初始化没有对象类型的数组列表 - JAVA

android - 扩展文件错误, "Download failed because the resources could not be found."

java - 使用 Spring MVC 自定义 JSON 响应

android - 通过安卓应用分享谷歌地图静态图片

html - Laravel 公共(public) CSS 样式表

html - 仅使用 CSS 替换 img,无法更改 HTML