Webview android

Webview is primarily used for loading a html content  in our application.
Let us discuss this in several parts. In this first part let load a normal web page toapplication using webview.
loadUrl is  the prime method to load a particular webpage to webview.
Hence make use of the snippet to load a page.
[sourcecode language="java"]
public class WebViewExample extends Activity {
public void onCreate(Bundle savedInstanceState) {
WebView webView = (WebView) findViewById(R.id.webview);
webView.setWebViewClient(new HelloWebViewClient());
But the above method loads the browser instead of opening the webpage inside the application.
To overcome this difficulty we should use the method shouldOverrideUrlLoading() along with webview and url string.
Now the application opens the web page inside the application itself.
[sourcecode language="java"]
public class HelloWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
Layout design
[sourcecode language="xml"]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:gravity="center" android:padding="10px">
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="AndroidPeople.com - Webview " android:textStyle="bold" android:textSize="20sp" android:textColor="#fff"></TextView><WebView android:id="@+id/webview" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
webview-androidpeople example

Post a Comment