문제

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 %"

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top