Is it possible to load a HTML file into a TextView in Android?

后端 未结 2 1068
萌比男神i
萌比男神i 2020-12-22 00:16

In my app I am loading a html document (contains: the code to display an equation, reference to libraries) into a webview.

The problem is that it still takes some t

相关标签:
2条回答
  • 2020-12-22 01:00

    Yes, this is possible :

    textView.setText(Html.fromHtml(myHTMLString));
    
    0 讨论(0)
  • 2020-12-22 01:03

    Yes, it is possible for achieving this you need to convert Input Stream from your local storage file path and create one String Builder to read every single line from Input Stream -

        // "string" is a your html file path
        File file = new File(string);
        try {
            FileInputStream fileInputStream = new FileInputStream(file);
            BufferedReader r = new BufferedReader(new 
            InputStreamReader(fileInputStream));
            StringBuilder strBuilder = new StringBuilder();
            String line;
            while ((line = r.readLine()) != null) {
                strBuilder.append(line).append("\n");
            }
            //"total" is your converted html you can show this on textview
            areTextView.fromHtml(String.valueOf(strBuilder));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    
    0 讨论(0)
提交回复
热议问题