Android 在ActionBar上显示进度微调器(刷新)?
我正在使用ActionBar。我想在标题栏上有一个刷新进度微调器,如果我将其设置为旋转-否则将其隐藏。有可能吗Android 在ActionBar上显示进度微调器(刷新)?,android,android-actionbar,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
// 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);
//我的菜单有一个刷新项,但它不应该在屏幕上可见
//除非它在旋转。
...
//当我需要展示我在活动中所做的一些工作时,
//我现在可以让微调器与
//刷新项是否在操作栏上可见?
getActionBarHelper().setRefreshActionItemState(true);
我不希望它出现在ActionBar上,除非它“正在进行”/“旋转”
谢谢对于没有代码标签、从电话发帖表示歉意 这是来自ActionbarSherlock(谷歌,如果你没有遇到它,允许在pre honeycomb中支持actionbar) 在创建主活动时
// 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,而不仅仅是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;
}
});
}
好的,谢谢。我会在那里挖一点。SDK提供的示例没有我最初认为的那么好。他们使用的是Window.FEATURE\u CUSTOM\u TITLE,其效果是在完全绘制之前向用户显示标题栏,这看起来非常不专业。唉。@Jake Wharton我正在努力解决这个问题。按下
刷新
按钮时,调用回调onOptionsItemSelected
。根据MartinS的建议,我们在哪里调用SetProgressBarIndeTerminateVibility
。如果您使用的是ActionBarSherlock,请确保使用SetSupportProgressBarIndeTerminateVibility()。否则,您的进度指示器将一直旋转,您将不知道原因。并且supportRequestWindowFeature(Window.FEATURE\u不确定\u进度)
(至少在使用ActionBarCompat时是如此)对于ActionBarCompat,您还需要支持RequestWindowFeature(Window.FEATURE\u PROGRESS)代码>或者您将获得NullPointerException(详细信息:)“窗口”属于哪个软件包?支持库v21不支持此功能,请注意。见-和