Open top menu


In this Tutorial we will explain how to load web url in webview android widgets.
expailn below--
you can used webview, the webview class is an extends  android View class.
The WebView is allowed to display web page in your activity in android.

first you have to add  Internet permission in our application manifest.xml.

<uses-permission android:name="android.permission.INTERNET" />

then you have add WebView android wedgets in created activity_main.xml class.
.................................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     >

</WebView>

then you have get WebView android wedgets  Id in created ActvityMain.java class.
.................................................................................................................................................................

package com.example.androidbeginnerpoint;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;


public class AdvertiseActivity extends Activity {
  WebView webview;


@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);


setContentView(R.layout.advertise);



webview=(WebView)findViewById(R.id.webview);

startWebView("androidbeginnerpoint.blogspot.in");



}
private void startWebView(String url) {
     
       
webview.setWebViewClient(new WebViewClient() {    
            ProgressDialog progressDialog;
       
           
            public boolean shouldOverrideUrlLoading(WebView view, String url) {            
                view.loadUrl(url);
                return true;
            }
     
            //Show loader on url load
            public void onLoadResource (WebView view, String url) {
                if (progressDialog == null) {
                 
                    progressDialog = new ProgressDialog(AdvertiseActivity.this);
                    progressDialog.setMessage("Loading...");
                    progressDialog.show();
                }
            }
            public void onPageFinished(WebView view, String url) {
                try{
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                    progressDialog = null;
                }
                }catch(Exception exception){
                    exception.printStackTrace();
                }
            }
           
        });
       
     
webview.getSettings().setJavaScriptEnabled(true);
       
   
       
       
webview.loadUrl(url);
       
       
    }
   

   
    @Override
 
    public void onBackPressed() {
        if(webview.canGoBack()) {
        webview.goBack();
        } else {
                         super.onBackPressed();
        }
    }


}






0 comments