Android: WebView unable to show ‘%’ percentage sign
When you use WebView and pass HTML to it if that HTML code contains “%” – percentage sign you would have “Web Page not Available” error.
let’s see this simple code
String message = "Show Percent: 38% "; WebView mWebView = (WebView) activity.findViewById(R.id.my_web_view); mWebView.loadData(message, "text/html", "en_US");
simply the error still exists.
after searching the internet, I found a nice and easy solution.
String message = "Show Percent: 38% "; message = message.replaceAll("%", "%"); WebView mWebView = (WebView) activity.findViewById(R.id.my_web_view); mWebView.loadData(message, "text/html", "en_US");
the solution is to replace all the % sings in the HTML code with
%
(How HTML sees the %).
message = message.replaceAll("%", "%");