Android webview not displaying '%' character
I have a WebView
using following code:
WebView webView = new WebView(cont);
开发者_开发百科webView.loadData("Red 20%", "text/html", "utf-8");
It is having trouble showing the string. But if I remove the '%' character from the string it is showing properly. What is wrong with the code? How do I display '%' in WebView
?
Simple:
WebView webView = new WebView(cont);
webView.loadData("Red 20%", "text/html", "utf-8");
You can see the special characters here: http://www.degraeve.com/reference/specialcharacters.php
URL encode the %
20%25 should do the trick
An easier alternative is to use TextUtils.htmlEncode()
for the strings you want to display.
WebView webView = new WebView(cont);
String s = TextUtils.htmlEncode("Red 20%");
webView.loadData(s, "text/html", "utf-8");
Instead of %
you have to useits equevalent to show it in web. actually it is %
so that your code should change to
webView.loadData("Red 20%", "text/html", "utf-8");
You can replace "Red 20%" -> "Red 20 %"
精彩评论