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

use*_*594 4 html java android textview

是否有可能将res/raw中的html加载到TextView中?我知道我可以使用WebView,但该死的透明度并不总是有效(不是在每台设备上)

Rah*_*hul 9

myTextView.setText(Html.fromHtml(readTxt()));     
Run Code Online (Sandbox Code Playgroud)

//此函数将返回您可以在textview中设置的字符串.并且该String具有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();
  }
Run Code Online (Sandbox Code Playgroud)