2011-05-01 64 views
1

你好 嗯,我是非常基本的Java,這裏是我的Java代碼關於我的活動類,我不能在webview中添加進度條,請幫我在我的代碼 Here我的Java代碼:在WebView的Tab主機上添加進度條

import android.app.Activity; 
import android.os.Bundle; 
import android.webkit.WebView; 
import android.widget.Toast; 
//Set Activity Irancell: 
public class Irancell extends Activity { 
WebView Irancell_Charge; 
//Start App Code at here: 
@Override 
// Set iCicle: 
public void onCreate(Bundle icicle) { 
super.onCreate(icicle); 
//Load Irancel Buy Creadit Page: 
Irancell_Charge=new WebView(this); 
setContentView(Irancell_Charge); 
Irancell_Charge.getSettings().setJavaScriptEnabled(true); 
Irancell_Charge.loadUrl("http://www.echarge.ir/Templates/irancellshop/m/"); 
//Text Label: 
Toast 
.makeText(this, "MTN Irancell Recharge Cards...", Toast.LENGTH_LONG) 
.show(); 
} 
} 

謝謝...

回答

0

要與你要實現這些代碼的動畫進度條顯示的進展:

ProgressDialog progressDialog; 
progressDialog = new ProgressDialog(mContext); 
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
progressDialog.setMessage("Loading..."); 
progressDialog.setCancelable(false); 
1

這將顯示頁面正在導航時的微調。每次用戶導航到新頁面時,都會顯示加載程序/進度。

我使用WebViewClient來實現這一點。

package sherif.android.activity; 

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; 

public class WebClientTestActivity extends Activity { 
    private ProgressDialog mSpinner; 
    private WebView webView; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     //initialise your spinner 
     mSpinner = new ProgressDialog(this); 
     mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     mSpinner.setMessage("Loading..."); 
     //initialise your webview 
     webView = new WebView(this); 
     webView.getSettings().setJavaScriptEnabled(true); 
     webView.loadUrl("http://sherifandroid.blogspot.com/"); 
     webView.setWebViewClient(new SherifWebClient()); 
     setContentView(webView); 
    } 
    private class SherifWebClient extends WebViewClient { 

     @Override 
     public void onPageStarted(WebView view, String url, Bitmap favicon) { 
      super.onPageStarted(view, url, favicon); 
      mSpinner.show(); 
     } 

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

    } 
}