简体   繁体   中英

Indeterminate progress in Android Activity

I am trying to replicate the experience found when you are uninstalling an app in ICS. Specifically the indeterminate progress indicator under the title bar. I have tried using requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS) and the various methods on Activity but to no avail. It instead shows a spinning progress bar in the top right hand corner of the screen/title bar. Am I missing something simple here? Or is this completely custom?

Here is the code I am using:

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);

    setProgressBarIndeterminate(true);
    setProgressBarIndeterminateVisibility(true);
}

卸载屏幕截图

You are using the ActionBar indeterminate progress bar, but you are looking for a ProgressBar View.

You can create the View programmatically or add it to a layout file like --

<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:indeterminate="true" />

Typically, you can decide when it is shown by calling .setVisibility(View.VISIBLE) to show and .setVisibility(View.GONE) when you are done.

If you have a minimum API of 11 and set your activity or app theme to @android:style/Theme.Holo you will get exactly that ProgressBar shown in your image.

If you want a similar effect on pre-API 11 devices, check out HoloEverywhere

Disclaimer: @iagreen's answer is still the right one -- to get layout similar to the one in uninstall activity your best option is to just use it in a layout, not rely on window features)

But you were on a right track with windows features, you just mixed two of them up.

See, this:

setProgressBarIndeterminate(true);

requests the window's [horizontal] progress bar to be indeterminate. And this:

setProgressBarIndeterminateVisibility(true);

shows the window's indeterminate progress bar -- thing is, it's a completely diffrerent view.

To clarify things further, this gets you a horizontal indeterminate progress bar shown at the top of the window

requestWindowFeature(Window.FEATURE_PROGRESS);
setProgressBarIndeterminate(true);
setProgressBarVisibility(true);

and this gets you a spinner-style progress bar in the actionbar

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setProgressBarIndeterminateVisibility(true);

That's a horizontal progress bar in the image, the Action Bar indeterminate progress bar is a Spinner style. You'd either need to make a custom view for the action bar, or put it as a view in your main layout. You can hide the action bar and make a custom header for a particular activity. Just use the Spinner style indeterminate progress bar, it's what everyone expects to see in the Action Bar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM