将进度对话框添加到sherlock片段的操作栏sherlock中

Gra*_*ant 3 android android-intent android-layout android-fragments android-fragmentactivity

有没有办法将进度对话框添加到操作栏sherlock sherlock fragment(不是片段活动).我必须使用sherlock片段,因为在我的应用程序中我使用导航抽屉.对于片段活动,当我使用以下代码时,进度对话框工作正常.

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.search_all_fragment_layout);              
setSupportProgressBarIndeterminateVisibility(true);
Run Code Online (Sandbox Code Playgroud)

在Fragments中有没有办法做到这一点?

谢谢.

Ste*_*ett 7

可以通过在Activity中使用以下行来显示ProgressBar:

supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setSupportProgressBarIndeterminate(true);
setSupportProgressBarIndeterminateVisibility(true);
Run Code Online (Sandbox Code Playgroud)

如果你想在你的片段中使用它,你必须参考活动:

getActivity().supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
getActivity().setSupportProgressBarIndeterminate(true);
getActivity().setSupportProgressBarIndeterminateVisibility(true);
Run Code Online (Sandbox Code Playgroud)

考虑在您从Activity中调用的方法中创建一个方法.

编辑:

在您的Activity中有一个方法,如下所示:

public void activateProgressBar(boolean activite){
    setSupportProgressBarIndeterminateVisibility(activate);
}
Run Code Online (Sandbox Code Playgroud)

确保在Activity的onCreate()中调用了它:

supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setSupportProgressBarIndeterminate(true);
Run Code Online (Sandbox Code Playgroud)

现在只需在你的片段中调用它:

((YourActivity)getActivity()).activateProgressBar(true / false);
Run Code Online (Sandbox Code Playgroud)