android 沙漏动画,android沙漏

2 个答案:

答案 0 :(得分:44)

ProgressDialog dialog = new ProgressDialog(this);

dialog.setMessage("Thinking...");

dialog.setIndeterminate(true);

dialog.setCancelable(false);

dialog.show();

上面的代码会在Activity:之上显示以下对话框

c4b4b8fae04def5fdba98506ba5708ef.png

或者(或另外),您可以在Activity的标题栏中显示进度指示器。

94313391b60d2d14d40aaf77c1d89951.png

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

然后像这样打开它:

setProgressBarIndeterminateVisibility(true);

然后将其关闭:

setProgressBarIndeterminateVisibility(false);

答案 1 :(得分:3)

以下是使用AsyncTask执行此操作的简单示例:

public class MyActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {

...

new MyLoadTask(this).execute(); //If you have parameters you can pass them inside execute method

}

private class MyLoadTask extends AsyncTask {

private ProgressDialog dialog;

public MyLoadTask(MyActivity act) {

dialog = new ProgressDialog(act);

}

protected void onPreExecute() {

dialog.setMessage("Loading...");

dialog.show();

}

@Override

protected String doInBackground(Object... params) {

//Perform your task here....

//Return value ... you can return any Object, I used String in this case

try {

Thread.sleep(6000);

} catch (InterruptedException e) {

e.printStackTrace();

}

return(new String("test"));

}

@Override

protected void onPostExecute(String str) {

//Update your UI here.... Get value from doInBackground ....

if (dialog.isShowing()) {

dialog.dismiss();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值