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

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


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();    } }


I got the same problem too.

Because i set the android:theme="@android:style/Theme.NoTitleBar"

I solve it by add a ProgressBar in the layout xml file, such as:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:orientation="vertical"  android:layout_width="fill_parent"  android:layout_height="fill_parent"  ><ProgressBar android:id="@+id/progressbar"    style="?android:attr/progressBarStyleHorizontal"    android:layout_width="fill_parent"    android:layout_height="3px"    android:max="100"    android:visibility="gone"/><WebView       android:id="@+id/webview"      android:layout_width="fill_parent"      android:layout_height="fill_parent"  />  </LinearLayout>

In code:

// when load url

progressBar.setProgress(0);progressBar.setVisible(View.VISIBLE);

...

// loading...progress changed

progressBar.setProgress(progress);

...

// when page finish

progressBar.setVisible(View.GONE);

C'est finish!


I have solved the issue.

Your call to setProgressBarVisibility() must be in onStart() or onResume() because, before that point, it seems you are not guaranteed to have any view on which you can change a visibility.


For this incredible solution by Dralangus, here's some fully tested production code. Thank you so much, Dralangus! Finally, a spinner that does not go away upon device rotation.

public class MainActivity extends Activity{private static boolean showSpinner; // needs staticpublic void spinnerOn()    {    showSpinner = true;    setProgressBarIndeterminateVisibility(true);    }public void spinnerOff()    {    showSpinner = false;    setProgressBarIndeterminateVisibility(false);    }protected void onResume()    {    // solved by Dralangus http://stackoverflow.com/a/7414659/294884    super.onResume();    if (showSpinner)        {        spinnerOn();        }    else        {        spinnerOff();        }    }protected void onStart()    {    super.onStart();    // note, onResume is called EVEN LATER than onStart,    // so your most reliable choice is onResume.    // eternal thanks to Dralangus for this solution    }@Overrideprotected void onCreate(Bundle savedInstanceState)    {    super.onCreate(savedInstanceState);    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);    setContentView(R.layout.activity_main);    ... // Your code    }