Showing posts with label WebView. Show all posts
Showing posts with label WebView. Show all posts

Saturday, January 2, 2016

Prevent webview from showing "web page not available"

Apply the below Code,

WebView.setWebViewClient(new WebViewClient() {
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        WebView.loadUrl("file:///android_asset/myerrorpage.html");

    }
});

Wednesday, July 9, 2014

WebView Unicode Support

mWebView.loadDataWithBaseURL(null, "தமிழில் கணினி", "text/html", "utf-8", null);
OR
WebSettings settings = mWebView.getSettings();
settings.setDefaultTextEncodingName("utf-8");

Wednesday, June 4, 2014

How to write static HTML code in WebView control

Apply the below code,

webView = (WebView) findViewById(R.id.webView1);
webViewSettings = webView.getSettings();
webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webViewSettings.setJavaScriptEnabled(true);
webViewSettings.setBuiltInZoomControls(true);
webViewSettings.setPluginState(PluginState.ON);
webView.getSettings().setJavaScriptEnabled(true);
String data="<h1>welcome to Android example..Write your own HTML code here..</h1><br>";
webView.loadData(data, "text/html","utf-8");

Thursday, May 29, 2014

How to enable Java Script in WebView

       myWebView = (WebView) findViewById(R.id.WebView1);
       WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);

How to Zoom out WebView content

        myWebView.setInitialScale(60);
        myWebView.getSettings().setLoadWithOverviewMode(true);
        myWebView.getSettings().setUseWideViewPort(true);

How to load a web page in webview control

WebView myWebView;      

myWebView = (WebView) findViewById(R.id.WebView1);
myWebView.loadUrl("http://www.google.com");

Monday, November 25, 2013

How to override 'web site not found' message in webview control


Add the following code inside of 'onCreate(Bundle savedInstanceState)' function,

 locationview.setWebViewClient(new WebViewClient()
{
   public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
  {
locationview.loadUrl("file:///assets/error.html");

  }  });

The above URL will be load if the web page not found in the webview control.