WebViewページの読み込み例

1882 ワード

 webview = (WebView) findViewById(R.id.webview);
		 webview.setBackgroundColor(0);
     //  WebView  ,    Javascript    
     webview.getSettings().setJavaScriptEnabled(true);
  //           
  			WebSettings ws = webview.getSettings();
  			ws.setUseWideViewPort(true);
  			ws.setLoadWithOverviewMode(true);
  			ws.setJavaScriptEnabled(true);
  			ws.setPluginState(PluginState.ON);
  			ws.setJavaScriptCanOpenWindowsAutomatically(true);
  			ws.setAllowFileAccess(true);
  			ws.setDefaultTextEncodingName("UTF-8");
  			ws.setLoadWithOverviewMode(true);
  			ws.setUseWideViewPort(true);
		mProgressDialog = new ProgressDialog(LoveCarLifeActivity.this);
	  	mProgressDialog.setMessage("    ...");
	  	mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
	  	mProgressDialog.setCancelable(true);
	  	mProgressDialog.show();
     //           
     webview.loadUrl("       , http  ");  
      
     //  Web    
     webview.setWebViewClient(new HelloWebViewClient ()); 
	}
	@Override 
  //      
  //  Activity  onKeyDown(int keyCoder,KeyEvent event)    
  public boolean onKeyDown(int keyCode, KeyEvent event) {  
      if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {  
          webview.goBack(); //goBack()    WebView       
          return true;  
      }else if(keyCode==KeyEvent.KEYCODE_BACK){
		  finish();
		  return  true;
	  }
      return false;  
  }  
    
  //Web    
  private class HelloWebViewClient extends WebViewClient { 
      @Override 
      public boolean shouldOverrideUrlLoading(WebView view, String url) {  
          view.loadUrl(url);  
          return true;  
      }  
      @Override
    public void onPageFinished(WebView view, String url) {
        if(mProgressDialog.isShowing()){
        	mProgressDialog.dismiss();
        }
    }
      
  }