Changing text color in a WebView?

后端 未结 8 442
梦如初夏
梦如初夏 2020-12-17 09:06

There\'s a method for altering background color but not font.
Any ideas?

相关标签:
8条回答
  • 2020-12-17 09:40

    You can concatenate your answer one body tag HTML with CSS style hex color, this is an example using a JSON response

    First: function for decode JSON to HTML format

    public String stripHtml(String html) {
        return Html.fromHtml(html).toString();
    }
    

    Second: Load data in WebView (no url)

     String string_html;
     string_html = "<body style="color:#535362;">" + youStringHTML + "</body>";
     webView.loadDataWithBaseURL(null, stripHtml(string_html), "text/html", "utf-8", null);
    
    0 讨论(0)
  • 2020-12-17 09:41

    @rafraph's answer didn't work for me. I had to use

    webView.loadUrl("javascript:document.body.style.setProperty(\"color\", \"white\");");
    
    0 讨论(0)
提交回复
热议问题