2011-07-10 67 views
2

我使用this教程,這是相當不錯的進步,我想將其轉換爲紡車有什麼辦法才達到這樣的, enter image description here轉換進度條紡車

should i have to go for 


    ProgressDialog dialog = ProgressDialog.show(MyActivity.this, "", 
          "Loading. Please wait...", true) 

我已經更新這樣的,但它不工作

public class Webview extends Activity { 

    WebView mWebView; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 

     // Adds Progrss bar Support 
     this.getWindow().requestFeature(Window.FEATURE_PROGRESS); 
     setContentView(R.layout.weblayout); 

     // Makes Progress bar Visible 
     getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); 

     // Get Web view 
     mWebView = (WebView) findViewById(R.id.MyWebview); //This is the id you gave 
                  //to the WebView in the main.xml 
     mWebView.getSettings().setJavaScriptEnabled(true); 
     mWebView.getSettings().setSupportZoom(true);   //Zoom Control on web (You don't need this 
                  //if ROM supports Multi-Touch  
     mWebView.getSettings().setBuiltInZoomControls(true); //Enable Multitouch if supported by ROM 

     // Load URL 
     mWebView.loadUrl("http://www.firstdroid.com/advertisement.htm"); 


     // Sets the Chrome Client, and defines the onProgressChanged 
     // This makes the Progress bar be updated. 
     final Activity MyActivity = this; 
     mWebView.setWebChromeClient(new WebChromeClient() { 
     public void onProgressChanged(WebView view, int progress) 
     { 


      ProgressDialog dialog = new ProgressDialog(MyActivity); 
      dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
      dialog.setMessage("Loading. Please wait..."); 
      dialog.setIndeterminate(true); 

      MyActivity.setProgress(progress * 100); //Make the bar disappear after URL is loaded 

      // Return the app name after finish loading 
      if(progress == 100) 
       MyActivity.setTitle(R.string.app_name); 
      } 
     }); 



    }//End of Method onCreate 
} 
+0

一個可以解決這個問題,這個http://www.chrisdanielson.com/2010/05/04/android-webview-and-the-indeterminant-progress-solution/ – user667340

+0

你是什麼MyActivity.setProgress()方法?我想你會用錯誤的參數來調用它,因爲進度是0-100範圍內的整數。另外我認爲使用靜態方法來達到這個目的是不可接受的。 – kord

回答

2

紡車(被稱爲STYLE_SPINNER)是ProgressDialog的默認實現實例化的時候,所以你的代碼寫的應該可以正常工作。

要通常設置ProgressDialog的樣式,您可以在調用show方法之前調用您創建的ProgressDialog上的setProgressStyle方法。像這樣:

ProgressDialog dialog = new ProgressDialog(this); 
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
dialog.setMessage("Loading. Please wait..."); 
dialog.setIndeterminate(true); 
+0

非常感謝您的關注,請您指出代碼中的哪一行代替上面的行。再一次感謝 – user667340

+1

請看看更新後的問題,我已經嘗試過,但它不工作,請指導我 – user667340