Android的沙漏沙漏、Android

2023-09-04 08:03:20 作者:遠客歸心

如何以编程方式在Android应用程序显示一个沙漏?

How can I programmatically display an hourglass in an Android application ?

推荐答案

您可以使用ProgressDialog:

ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("Thinking...");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.show();

以上code将显示在您的活动的顶部下面的对话框:

The above code will show the following dialog on top of your Activity:

另外(或附加地),可以显示在你的活动的标题栏中的进度指示器

Alternatively (or additionally) you can display a Progress indicator in the title bar of your Activity.

您need请以此为靠近你的活动的的onCreate()方法的顶部的功能 使用下面code:

You need to request this as a feature near the top of the onCreate() method of your Activity using the following code:

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

然后打开它是这样的:

Then turn it on like this:

setProgressBarIndeterminateVisibility(true);

和关闭它是这样的:

setProgressBarIndeterminateVisibility(false);