How to Add a WebView
1. Open the res/layout/main.xml file or the file you would like to add the WebView to.2. Add the following default WebView code to the file below the beginning LinearLayout and before the ending </LinearLayout>.
Example:
<LinearLayout ......>
<WebView
android:id="@+id/webView"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_gravity="left|center_vertical"/>
</LinearLayout>
3. Open the MainActivity.java file under the src/com directory.
4 Declare a class-level, WebView named webView.
5. Add Internet Permission to your Android Project
6. Add the bolded code below to the OnCreate. This code will link your webView in your main.xml file to the webView in code.
The webView.loadUrl will load the google web site on startup.
webView = (WebView) findViewById(R.id.webView);
webView.loadUrl("http://www.google.com");
7. Run your app to test it. It should display a WebView with the Google page.
8. However, you will notice when you do a search for something one of two things will happen when you do a search for something. Let's say you search for 'birds'.
1. Your default browser on your device will open with the search contents.
2. A pop-up box appears and asks which browser you would like to use.
If you choose a browser, that browser will open and browsing will be through that one instead of your WebView. To keep the browsing experience in your WebView, you will need to add this line of code below.
Add the webView.getSettings line right before the webView.loadUrl line.
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");
9. Run and test your app again.
You should be able to search for 'birds' and the results show up in your own WebView.
Resources:
http://developer.android.com/guide/webapps/webview.html