All posts tagged WebView

  • 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.

    Webpage 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("%", "&#37");
    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

    &#37

    (How HTML sees the %).

    message = message.replaceAll("%", "&#37");