选项卡和标题android中的进度条

时间:2011-05-24 00:31:11

标签: android progress-bar android-tabhost

我正在尝试构建下面的教程代码,我有两个选项卡,每个都显示一个内部的webview,里面有这个代码。

但进度条不再显示在标题栏中。它仅在我单独查看Web视图时有效,但在我使用tabhost并将两者放在一起时则无效。我喜欢标题中的进度条,并且真的希望它能够正常工作。

我很新,所以任何提示或提示都有帮助。

Tutorial

   package firsrdroid.tutorial.mywebview;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

public class UsingMyWebview 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.main );

      // 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)   
        {
         //Make the bar disappear after URL is loaded, and changes string to Loading...
         MyActivity.setTitle("Loading...");
         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
}

1 个答案:

答案 0 :(得分:1)

之前我曾遇到类似问题的Tab Views;起初他们有点混乱,但让我试着解释一下。如果您通过另一个活动实现Tab View,换句话说,您有一个活动,称之为WebBrowser,其中包含两个选项卡,活动WebBrowser可以控制标题/进度条。因此,Tab Views(又名MyActivity)无法直接通过MyActivity.setTitle()控制WebBrowser的标题/进度条。实际上,在这种情况下,MyActivity实际上没有可见的标题栏来访问;它全部被WebBrowser包围。为了控制它,你必须通过WebBrowser调用它。如果我对此解释清楚,请告诉我!