Wednesday, 11 March 2015

Android WebView Example


The WebView enables you to embed a web browser in your activity. This is very useful if your appli- cation needs to embed some web content, such as maps from some other providers, and so on. The following Try It Out shows how you can programmatically load the content of a web page and dis- play it in your activity.

Using the WebView View

1 . Using Eclipse, create a new Android project and name it as WebView.

2 . Add the following statements to the main.xml file:

<?xml​ version=”1.0” ​encoding=”utf-8”?>
<LinearLayout ​xmlns:android=”” ​​​​android:orientation=”vertical” ​​​​
android:layout_width=”fill_parent” ​
​​​android:layout_height=”fill_parent” ​​​​>

android:id=”@+id/webview1” ​​
​​android:layout_width=”wrap_content” ​
​​​android:layout_height=”wrap_content” />


3 . In the file, add the following statements in bold:

package​ com.emergingandroidtech.WebView;
import ​android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

public ​class ​MainActivity​ extends​ Activity
/**​Called​ when​ the ​activity ​is ​first ​created.​*/

​@Override ​​
​​public ​void ​onCreate(Bundle​savedInstanceState)​
WebView wv = (WebView) findViewById(;
​​​​​​​​WebSettings webSettings = wv.getSettings(); ​​
​​​​​​​​wv.loadUrl( ​​​​​​​​“”);

No comments:

Post a Comment