Immanuel

Tuesday, October 30, 2012

Android Web View - Progress Dialog, Full Screen


Android provides WebView to load the Web pages inside the application itself, we can customize this webview according to our needs.

Traditionally we will use handlers to handle the events but in android we can use the pre-defined methods to handle the events,

In this post i have explained how to load progress dialog while page is being loaded and hoe to keep the web view in the full screen mode .

1.Full Screen:
                      To use the web view in the full screen just use the simple code given below.

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

The only condition using this is , you should use this code before setContentView as given in the project file attached with this blog post.

2.Using Progress Dialog:
                         As i mention earlier you can use progress dialog until your page gets loads. 

Once you complete the inflation process use the following code

               web.setWebViewClient(new WebViewClient() {

               public void onPageStarted(WebView view, String url, Bitmap favicon) {
                dialog = ProgressDialog.show(ProgressDemoActivity.this, null,
                        "Please Wait...Page is Loading...");
                dialog.setCancelable(true);
                super.onPageStarted(view, url, favicon);
            }


                public void onPageFinished(WebView view, String url) {
                dialog.dismiss();
                super.onPageFinished(view, url);
            }

The first method will be triggered once the page is start loading, as shown below


The Second method will be triggered once the page is completely loaded,once it is triggered the dialog will get disappeared, as shown below


You will get this dialog every time  you navigate inside the web view, as shown b 

 For more detail you can use this eclipse project here

Get the code in  GitHub

Happy hacking...


3 comments:

Twitter Bird Gadget