Created
October 30, 2012 11:42
-
-
Save immanuel2305/3979753 to your computer and use it in GitHub Desktop.
Android Web View- Full Screen & Progress Dialog on Loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.android.progress.demo" | |
android:versionCode="1" | |
android:versionName="1.0" > | |
<uses-sdk android:minSdkVersion="8" | |
android:targetSdkVersion="16" /> | |
<uses-permission android:name="android.permission.INTERNET"/> | |
<application | |
android:icon="@drawable/ic_launcher" | |
android:label="@string/app_name" > | |
<activity | |
android:name=".ProgressDemoActivity" | |
android:label="@string/app_name" > | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:orientation="vertical" > | |
<WebView | |
android:id="@+id/webview" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
/> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.android.progress.demo; | |
import android.app.Activity; | |
import android.app.ProgressDialog; | |
import android.graphics.Bitmap; | |
import android.os.Bundle; | |
import android.view.Window; | |
import android.webkit.WebView; | |
import android.webkit.WebViewClient; | |
import android.widget.Toast; | |
public class ProgressDemoActivity extends Activity { | |
WebView web; | |
ProgressDialog dialog; | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
//Hide Title Bar - This Should be done before SetContentView | |
this.requestWindowFeature(Window.FEATURE_NO_TITLE); | |
setContentView(R.layout.main); | |
// Inflation | |
web = (WebView) findViewById(R.id.webview); | |
web.setWebViewClient(new WebViewClient() { | |
// This method will be triggered when the Page Started Loading | |
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); | |
} | |
// This method will be triggered when the Page loading is completed | |
public void onPageFinished(WebView view, String url) { | |
dialog.dismiss(); | |
super.onPageFinished(view, url); | |
} | |
// This method will be triggered when error page appear | |
public void onReceivedError(WebView view, int errorCode, | |
String description, String failingUrl) { | |
dialog.dismiss(); | |
// You can redirect to your own page instead getting the default | |
// error page | |
Toast.makeText(ProgressDemoActivity.this, | |
"The Requested Page Does Not Exist", Toast.LENGTH_LONG).show(); | |
web.loadUrl("http://arunimmanuel.blogspot.in"); | |
super.onReceivedError(view, errorCode, description, failingUrl); | |
} | |
}); | |
web.loadUrl("http://arunimmanuel.blogspot.in"); | |
web.getSettings().setLoadWithOverviewMode(true); | |
web.getSettings().setUseWideViewPort(true); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<string name="hello">Web Page URL</string> | |
<string name="app_name">ProgressDemo</string> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks..