如何避免ProgressDialog在Android中ProgressDialog、Android

2023-09-08 09:53:39 作者:旧街凉风

对话框@ Android开发者说要避免ProgressDialog指示加载,而是,把一个活动的指标权布局。

Dialogs @ Android Developer says to avoid ProgressDialog to indicate loading, and instead, to put an activity indicator right in the layout.

进展和放大器;活动@ Android开发者讨论活动指标,但没有指定使用的类。我已经没有运气像ActivityBar,ActivityCircle或ActivityIndi​​cator名称搜索Android的类。

Progress & Activity @ Android Developer discusses activity indicators, but doesn't name the classes used. I've had no luck searching for Android classes with names like ActivityBar, ActivityCircle, or ActivityIndicator.

我在哪里可以找到Android的支持文档(教程,范例,或者API文档),用于包括活动指标权在我的布局,避免ProgressDialog?

Where can I find documentation (tutorials, examples, or API documentation) on Android's support for including activity indicators right in my layout, avoiding a ProgressDialog?

更新: full.stack.ex我指出了正确的答案

Update: full.stack.ex pointed me the right answer.

首先,请在活动的onCreate()方法的以下code调用的setContentView()之前:的

First, include the following code in the Activity's onCreate() method before invoking setContentView():

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

接下来,只需加载(例如发射了一个AsyncTaskLoader),使用此电话进行微调之前出现:

Next, just before loading (e.g. firing up an AsyncTaskLoader), use this call to make the spinner appear:

setProgressBarIndeterminateVisibility(true);

最后,装载完成后,再次隐藏微调:

Finally, after the load is completed, hide the spinner again:

MainActivity.this.setProgressBarIndeterminateVisibility(false);

宾果!无需ProgressDialog。使得微调可见,似乎装载在模拟器大大减缓(需要花费几分钟,而不是秒),而不是我的实际电话。我不知道是否有什么办法可以使微调使用较少的CPU周期。

Bingo! No ProgressDialog required. Making the spinner visible seems to slow down loading considerably in the emulator (it takes minutes instead of seconds), but not on my actual phone. I'm not sure if there's any way to make the spinner use fewer CPU cycles.

推荐答案

这不是真的从没有对一个窗口功能的文档显而易见的。

It's not really obvious from the documentation that there's a window feature for that.

这是一个内置的进度指示器:

It's a built-in progress indicator:

Activity.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

developer.android.com/reference/android/app/Activity.html#requestWindowFeature(int)

 
精彩推荐
图片推荐