2011-05-01 81 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(); 
     } 

    } 
}