Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: The progress bar in the window's title does not display

I have a web view to override the built-in browser and I want to show a progress indicator on the title bar.

This is the code:

    @Override public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     getWindow().requestFeature(Window.FEATURE_PROGRESS);      setContentView(R.layout.browser);     currentURL = BrowserActivity.this.getIntent().getExtras().getString("currentURL");      try {         mWebView = (WebView) findViewById(R.id.webview);         mWebView.getSettings().setJavaScriptEnabled(true);         mWebView.setWebViewClient(new browserActivityClient());         setProgressBarIndeterminateVisibility(true);         mWebView.loadUrl(currentURL);         setProgressBarIndeterminateVisibility(false);     } catch (Exception e) {         Log.e(getClass().getSimpleName(), "Browser: " + e.getMessage());         Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();     }  } 

It should work, I think, according to Android docs and other samples I saw on the net. But it doesn't, could you please tell me where am I wrong?

And another question: if sometimes later I'll choose to declare android:theme="@android:style/Theme.NoTitleBar" in the application manifest, will the progress bar show anymore or not?

Thank you.

like image 991
Manu Avatar asked Jun 22 '10 10:06

Manu


People also ask

What is the default orientation for displaying the progress bar?

Whether the progress bar is horizontal or vertical. The default is HORIZONTAL .

What are types of progress bar in android?

Progress bar supports two modes to represent progress: determinate, and indeterminate. For a visual overview of the difference between determinate and indeterminate progress modes, see Progress & activity.


1 Answers

In fact the correct code is (tested and working):

public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);     requestWindowFeature(Window.FEATURE_PROGRESS);     currentURL = BrowserActivity.this.getIntent().getExtras().getString("currentURL");      setContentView(R.layout.browser);      setProgressBarIndeterminateVisibility(true);     setProgressBarVisibility(true);      try {         mWebView = (WebView) findViewById(R.id.webview);         mWebView.getSettings().setJavaScriptEnabled(true);         mWebView.setWebViewClient(new browserActivityClient());          mWebView.setWebChromeClient(new WebChromeClient() {            public void onProgressChanged(WebView view, int progress) {                setProgress(progress * 100);               if(progress == 100) {                  setProgressBarIndeterminateVisibility(false);                  setProgressBarVisibility(false);               }            }         });         mWebView.loadUrl(currentURL);     } catch (Exception e) {         Log.e(getClass().getSimpleName(), "Browser: " + e.getMessage());         Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();     }  } 
like image 153
Manu Avatar answered Sep 20 '22 16:09

Manu