how set text color of webview in android

后端 未结 4 788
情歌与酒
情歌与酒 2021-01-13 06:57

i am trying to change text color of webview with this code

String message =\"\"+\"\"+
\"text in white\"+ \"
\"
4条回答
  •  孤街浪徒
    2021-01-13 07:46

    You have to give the path of that file like this.

    String extStorageDirectory = Environment.getExternalStorageDirectory()
                    .toString() + "/folder_name";
    
    File directory = new File(extStorageDirectory);
    File fileInDirectory = new File(directory,file_name.html);
    
    //Read text from file
    StringBuilder html_text = new StringBuilder();
    
    try {
        BufferedReader br = new BufferedReader(new FileReader(fileInDirectory));
        String line;
    
        while ((line = br.readLine()) != null) {
            html_text.append(line);
            html_text.append('\n');
        }
    }
    catch (IOException e) {
        //You'll need to add proper error handling here
    }
    

    then use this html code for edit

    String message =""+""+"text in white"+ "
    " +""+""+" text in blue color "+""; webview.loadData(message, "text/html", "utf8");

提交回复
热议问题