protected WebView getWebView() {
    if (mWebView == null) {

      if (progressBar == null) {
        progressBar = (ProgressBar) findViewById(R.id.progressBar1);
      }
      mWebView = (WebView) findViewById(R.id.webView1);
      mWebView.setWebViewClient(new WebViewClient() {});
      mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
      mWebView.setVerticalScrollbarOverlay(true);
      mWebView.setHorizontalScrollBarEnabled(false);
      mWebView.getSettings().setPluginState(PluginState.ON);

      // Javascriptの有効
      mWebView.getSettings().setJavaScriptEnabled(true);

      // ズームコントローラーの使用
      mWebView.getSettings().setBuiltInZoomControls(false);

      mWebView.setWebChromeClient(
          new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
              if (progressBar != null) {
                progressBar.setProgress(progress);
                if (progress == 100) {
                  Timer timer = new Timer(true);
                  timer.schedule(
                      new TimerTask() {
                        @Override
                        public void run() {
                          // mHandlerを通じてUI Threadへ処理をキューイング
                          mHandler.post(
                              new Runnable() {
                                public void run() {
                                  progressBar.setVisibility(View.GONE);
                                }
                              });
                        }
                      },
                      200);
                }
              }
            }
          });
    }

    return mWebView;
  }
Example #2
0
 public static void setupWebView(WebView webview) {
   webview.setVerticalScrollbarOverlay(true);
   WebSettings settings = webview.getSettings();
   settings.setLoadWithOverviewMode(true);
   settings.setUseWideViewPort(true);
 }