我正在使用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上,除非它正在“进行中”/旋转。
由于
答案 0 :(得分:76)
没有代码标签的道歉,从手机发布...
这是来自ActionbarSherlock(谷歌,如果你没有遇到它,允许在蜂窝前支持动作栏)
on onCreate of main activity
// 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);
}
答案 1 :(得分:3)
如果您从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;
}
});
}