Intermediate Progress doesn't work with Action

2019-02-17 11:39发布

问题:

I setup ActionBarSherlock with my app, and I'm trying to use the Intermediate Progress, I'm using this:

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);    
    setSupportProgressBarIndeterminateVisibility(false);

In my onCreate, and then using:

    setSupportProgressBarIndeterminateVisibility(true);

To enable it.

It works fine in ICS but it doesn't work at all in Gingerbread or Froyo, does anyone know how to get it to work? Thanks

回答1:

I just had the same problem. Jake's solution above did not fix it for me - the method is undefined.

I found a working solution posted by Jake on the bug list for ActionBarSherlock here:

  • Action Bar Indeterminate Progress Bar Not Disappearing

See Jake's response to the poster - the trick is to call getSupportActionBar() first, to "trigger creation of the views".

So my onCreate() method is:

protected void onCreate(Bundle arg0)
{
    super.onCreate(arg0);

    // allow window to show progress spinner in the action bar
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    getSupportActionBar();
    setSupportProgressBarIndeterminateVisibility(false); 
}

Update based on comment from Laux:

Make sure your imports reflect com.actionbarsherlock.view.Window.FEATURE_INDETERMINATE_PROGRESS for this to work.

Here is part of my import block from an app that uses this pattern:

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.ActionProvider;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
import com.actionbarsherlock.widget.ShareActionProvider;

This is a very good thing to remember when working with ABS - many of your normal Android imports should be updated to refer to ABS instead.

It may be a good idea to revisit your import block, or possibly remove it entirely and let Eclipse rebuild it for you (CTRL-SHIFT-O) to which point Eclipse will prompt you for each import that ABS redeclares.

This was also explained by Glebbb in his answer.



回答2:

I'm sure you've probably figured it out by now, but the most likely culprit is you including the wrong file because it's so easy to do automatically.

Replace any import of android.view.Window with com.actionbarsherlock.view.Window and the needed features will work.



回答3:

You need to call supportRequestWindowFeature.

requestWindowFeature is a final method on Activity and couldn't be overriden.



回答4:

Check, if you are using Theme.Sherlock.NoActionBar or similar no action bar theme for this activity. In this case setSupportProgressBarIndeterminateVisibility method fails for me with

Caused by: java.lang.NullPointerException
at com.actionbarsherlock.internal.ActionBarSherlockCompat.updateProgressBars(ActionBarSherlockCompat.java:710)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.onIntChanged(ActionBarSherlockCompat.java:686)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.updateInt(ActionBarSherlockCompat.java:681)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setFeatureInt(ActionBarSherlockCompat.java:665)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setProgressBarIndeterminateVisibility(ActionBarSherlockCompat.java:637)
at com.actionbarsherlock.app.SherlockFragmentActivity.setSupportProgressBarIndeterminateVisibility(SherlockFragmentActivity.java:282)

I guess you should use a progress dialog instead to indicate loading process or regular Theme with activity title bar and then use setProgressBarIndeterminateVisibility method for older platforms.