在ActionBar上显示进度微调(刷新)?

我正在使用ActionBar。 我想在标题栏上有一个刷新进度微调,如果我把它设置为旋转 – 否则隐藏它。 那可能吗?:

// My menu has a refresh item, but it shouldn't be visible on the // actionbar unless it's spinning. <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/menu_refresh" android:title="@string/refresh" android:icon="@drawable/ic_action_refresh" /> </menu> ... // When I need to show some work being done on my activity, // can I somehow now make the spinner associated with the // refresh item become visible on the action bar? getActionBarHelper().setRefreshActionItemState(true); 

除非“正在进行”/正在旋转,否则我不需要在ActionBar上。

谢谢

Solutions Collecting From Web of "在ActionBar上显示进度微调(刷新)?"

道歉没有代码标签,从电话发布…

这是来自ActionbarSherlock(谷歌,如果你没有遇到它,允许在蜂窝中的操作栏支持)

在主要活动的onCreate

 // This has to be called before setContentView and you must use the // class in android.support.v4.view and NOT android.view requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); 

显示/隐藏操作栏中的进度。 注意与actionbarsherlock你必须使用boolean.TRUE / FALSE,不只是真/假………

 if (getSupportLoaderManager().hasRunningLoaders()) { setProgressBarIndeterminateVisibility(Boolean.TRUE); } else { setProgressBarIndeterminateVisibility(Boolean.FALSE); } 

如果你从ActionBarActivity扩展,试试这个:

 public class MainActivity extends ActionBarActivity { boolean showUp=true; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_main); setSupportProgressBarIndeterminateVisibility(Boolean.TRUE); Button b = (Button) findViewById(R.id.myButton); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(showUp){ setSupportProgressBarIndeterminateVisibility(Boolean.FALSE); }else { setSupportProgressBarIndeterminateVisibility(Boolean.TRUE); } showUp=!showUp; } }); }