Android code for webview

webview for loading website in android
android code for webview to prevent popup for browser

For internet connection we have to add android.permission.INTERNET in Manifest

Step 1:

Goto AndroidManifest.xml ->click on Permission tab



Step 2:

Click on Add.. button  and select Uses Permission


Step 3:

select android.permission.INTERNET


android.permission.INTERNET is used for using internet connection

Step 4:

Add webview to res -> layout -> activity_main.xml

      <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

The webview id is webView1

Step 5:

Add below code for webview

WebView ourSite = (WebView) findViewById(R.id.webView1);
ourSite.setWebViewClient(new WebViewClient());
ourSite.loadUrl("http://www.aboutcodes.com");


ourSite variable is used to assigned webView1 

Import Header file

// For webview
import android.webkit.WebView;
// For WebViewClient
import android.webkit.WebViewClient;

Leave reply

Add your comments here

Back to Top