开发者

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 &#37 so that your code should change to

webView.loadData("Red 20%", "text/html", "utf-8"); 


You can replace "Red 20%" -> "Red 20 %"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜