Android hourglass

前端 未结 2 657
长发绾君心
长发绾君心 2021-01-30 09:44

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

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-30 10:16

    You can use a ProgressDialog:

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

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

    alt text

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

    alt text

    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);
    

    and turn it off like this:

    setProgressBarIndeterminateVisibility(false);
    

提交回复
热议问题