java Android:在 TabHost 活动中显示不确定的进度条

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1138809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 15:19:29  来源:igfitidea点击:

Android: Showing indeterminate progress bar in TabHost activity

javaandroid

提问by MattC

I know that the following code should show and hide a tiny circular progress bar with the following code in Android:

我知道下面的代码应该在 Android 中显示和隐藏一个带有以下代码的小圆形进度条:

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setProgressBarIndeterminateVisibility(true);
setProgressBarIndeterminateVisibility(false);

The problem is that I am using a TabHost and I need to be able to do this from one of the "child" activities. Is there any way I can go about doing this?

问题是我使用的是 TabHost,我需要能够从“子”活动之一中做到这一点。有什么办法可以做这件事吗?

I found this questionon the intarwebs but as you can see, it went unanswered.

我在 intarwebs 上发现了这个问题,但正如你所看到的,它没有得到解答。

采纳答案by MattC

And I found the answer. In your parent activity, before you do anything, you need to do the requestWindowFeature call, and then in your child activity you call getParent().setProgressBarIndeterminateVisibility(true/false);

我找到了答案。在你的父活动中,在你做任何事情之前,你需要做 requestWindowFeature 调用,然后在你的子活动中调用getParent().setProgressBarIndeterminateVisibility(true/false);

回答by droidgren

Just for completeness:

只是为了完整性:

If the task is running in a different thread other than Main ui thread, you can do:

如果任务在 Main ui 线程以外的其他线程中运行,您可以执行以下操作:

    this.runOnUiThread(new Runnable() {
        public void run() {
            getParent().setProgressBarIndeterminateVisibility(mToggleIndeterminate);
        }
    });