WebView is a view that dispaly web page inside your application. You can also specify HTML
string and can show it inside your application using WebView.
<WebView> element to your xml layout file. Ex:<?xml version="1.0" encoding="utf8"?> <WebView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="fill_parent" />
Load Web page in the WebView,use loadurl(). EX:WebView myWebView = (WebView) findViewById(R.id.webview); myWebView.loadUrl("http://www.example.com");
By default the Android WebView component has JavaScript disabled. You can enable through the WebSetting attached to your WebView.
Ex:WebView myWebView = (WebView) findViewById(R.id.webview); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); setMinimumFontSize(int size): Set the minimum font size. The default is 8. webSettings.setMinimumFontSize(10); setMediaPlaybackRequiresGesture(boolean require): Set whether the WebView requires a user gesture to play media. The default is true. webSettings. setMediaPlaybackRequiresGesture(); setTextZoom(int textZoom): Set the text zoom of the page in percent. The default is 100. webSettins.setTextZoom(150);
When the user click a link in the web page loaded into the WebView.the default behaviour is to load that URL of the link in the system Android browser.
To open links clicked by the user, simply provide a WebViewClient for your WebView, using setWebViewClient(). Ex:WebView myWebView = (WebView) findViewById(R.id.webview); myWebView.setWebViewClient(new WebViewClient()); private class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView webView, String url) { return false; } }
Tags: WebView in android