Wednesday, April 10, 2013

Android WebView tutorial

A WebView component is what Android uses to display a web content. In order to create one in your app, you first have to create an id for it in your xml file. 

e.g. <WebView android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"></WebView>

After create your instance inside the XML file, go to your main activity Java class. Above the @override declare your WebView so it can be used globally.

eg. WebView webview1;

Within the onCreate method add the following code.

webview1 = (WebView)findViewById(R.id.webView1);
webview1.loadUrl("http://whatever.com");
webview1.setwebViewClient(new webViewClient());
webview1.setWebChromeClient(new webChromeClient());

Hit launch and your app should be ready.

No comments:

Post a Comment