Android DialogFragment进度条
我到处搜索过,但找不到解决这个问题的方法。
基本上我有一个登录屏幕,我试图在登录服务器(通过线程)时显示进度旋转器,然后在登录成功后将其关闭。它必须在改变方向时发挥作用。
我正在使用 DialogFragment
和 Android 兼容包来制作进度条(找不到任何相关文档,仅适用于基本\警报对话框),因为 showDialog()
现在已弃用。现在我只是显示一个自定义消息框作为登录微调器。
总结:
- 如何使用 DialogFragment 设置进度微调器。
- 方向更改后如何在另一个线程中将其关闭。
I've searched everywhere and I can't find a solution to this problem.
Basically I have a login screen and I'm trying to get a progress spinner to show up while it's logging in to the server (via a thread), and then dismiss it after the login is successful. It has to work while changing orientations.
I am using DialogFragment
with the Android compatibility package to make a progress bar (can't find any documentation on it, only for basic\alert dialog) because showDialog()
is deprecated now. Right now I just show a custom message box as a login spinner.
In Summary:
- How can I set up a Progress spinner with
DialogFragment
. - How can I dismiss it in another thread after orientation changes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要显示进度微调器,只需覆盖 DialogFragment .onCreateDialog() 在您的对话框片段中,如下所示(无需覆盖
onCreateView()
):至于从其他地方消除该对话框片段,您需要获得一个持有
FragmentManager
(从下一个FragmentActivity
或Fragment
内部)并调用popBackStack()
(如果你没有在其中进行任何其他片段事务)其间)。如果进度对话框片段和下一个活动之间存在更多步骤/片段事务,您可能需要其他
popBackStack(...)
方法之一,该方法采用 ID 或标记来弹出所有内容将进度对话框片段从堆栈中删除。For showing a progress spinner, just override DialogFragment.onCreateDialog() in your dialog fragment like this (no need for overriding
onCreateView()
):As for dismissing that dialog fragment from somewhere else, you'll need to get a hold of
FragmentManager
(from inside your nextFragmentActivity
orFragment
) and callpopBackStack()
on it (if you don't do any other fragment transaction in the meantime).If there's more steps/fragment transactions between your progress dialog fragment and the next activity, you'll probably need one of the other
popBackStack(...)
methods that take an ID or tag to pop everything up to your progress dialog fragment off the stack.我知道这是一个老问题,但我想
根据 Android Development Protip 分享更好的解决方案:
正如 Roman Nurik 所说:
I know this is old question but I want to share much better solution for this
According to Android Development Protip:
As Roman Nurik states: