Skip to content

Instantly share code, notes, and snippets.

@yoggy
Created December 7, 2010 12:19
Show Gist options
  • Save yoggy/731739 to your computer and use it in GitHub Desktop.
Save yoggy/731739 to your computer and use it in GitHub Desktop.
/*
* WebViewTest.java
* see also: http://developer.android.com/reference/android/webkit/WebView.html
*/
package net.sabamiso.android.WebViewTest;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class WebViewTest extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// フルスクリーンをセット
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
// プログレスバーを有効に
getWindow().requestFeature(Window.FEATURE_PROGRESS);
// WebViewクラスを作成
WebView webview = new WebView(this);
webview.getSettings().setJavaScriptEnabled(true);
// WebViewクラスにイベントリスナーをつける
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
activity.setProgress(progress * 1000);
}
});
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
// WebViewクラスをActivityにセットする
setContentView(webview);
// ページのロード
webview.loadUrl("file:///sdcard/index.html");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment