【问题标题】:Add progress dialog in to the action bar sherlock from sherlock fragment从 sherlock 片段将进度对话框添加到操作栏 sherlock
【发布时间】:2013-11-15 07:51:44
【问题描述】:

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

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.search_all_fragment_layout);              
setSupportProgressBarIndeterminateVisibility(true);

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

谢谢。

【问题讨论】:

    标签: android android-layout android-intent android-fragments android-fragmentactivity


    【解决方案1】:

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

    supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setSupportProgressBarIndeterminate(true);
    setSupportProgressBarIndeterminateVisibility(true);
    

    如果你想在 Fragment 中使用它,你必须参考 Activity:

    getActivity().supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    getActivity().setSupportProgressBarIndeterminate(true);
    getActivity().setSupportProgressBarIndeterminateVisibility(true);
    

    考虑在 Activity 中创建一个从 Fragment 调用的方法。

    编辑:

    在你的 Activity 中有这样的方法:

    public void activateProgressBar(boolean activite){
        setSupportProgressBarIndeterminateVisibility(activate);
    }
    

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

    supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setSupportProgressBarIndeterminate(true);
    

    现在只需在 Fragment 中调用它:

    ((YourActivity)getActivity()).activateProgressBar(true / false);
    

    【讨论】:

    • 首先感谢您的回答,您能否解释一下“考虑在您的 Activity 中创建一个从 Fragment 调用的方法”这一行是什么意思。
    • 在片段中我不能使用这个 getActivity().activateProgressBar(true);它说“FragmentActivity 类型的方法 activateProgressBar(boolean) 未定义”我该怎么办
    • 非常感谢您的描述性答案并花时间在这件事上,它现在正在工作
    猜你喜欢
    • 1970-01-01
    • 2012-06-06
    • 1970-01-01
    • 2013-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多