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

use*_*701 31 android android-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);
Run Code Online (Sandbox Code Playgroud)

除非它正在"进行中"/旋转,否则我不希望它在ActionBar上.

谢谢

Mar*_*inS 76

没有代码标签的道歉,从手机发布......

这是来自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);
Run Code Online (Sandbox Code Playgroud)

在操作栏中显示/隐藏进度.注意使用actionbarsherlock你必须使用boolean.TRUE/FALSE,而不仅仅是true/false .........

if (getSupportLoaderManager().hasRunningLoaders()) {
   setProgressBarIndeterminateVisibility(Boolean.TRUE); 
} else {
   setProgressBarIndeterminateVisibility(Boolean.FALSE); 
}
Run Code Online (Sandbox Code Playgroud)

  • 如果您正在使用ActionBarSherlock,请确保使用setSupportProgressBarIndeterminateVisibility().否则,您的进度指示器将一直旋转,您将不知道原因. (19认同)
  • 和`supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);`(至少在使用`ActionBarCompat`时) (5认同)
  • 对于ActionBarCompat,您还需要`supportRequestWindowFeature(Window.FEATURE_PROGRESS);`或者您将获得NullPointerException(详情:http://stackoverflow.com/questions/18192148/nullpointerexception-with-progressbar-using-actionbarcompat) (4认同)