单击该按钮时我有按钮我只想显示进度对话框 2 秒,如何在 2 秒后关闭进度对话框
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressDialog = new ProgressDialog(ActivityTalentHunt.this);
progressDialog.setMessage("Page is loading...");
progressDialog.show();
Thread mythread=new Thread(){
@Override
public void run() {
try {
sleep(2000);
}catch (Exception e) {
e.printStackTrace();
}finally {
runOnUiThread(new Runnable() {
@Override
public void run() {
progressDialog.dismiss();
}
});
}
}
};
mythread.start();
}
您可以使用 Handler
你需要导入 import android.os.Handler;
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
final ProgressDialog progressDialog = new ProgressDialog(ActivityTalentHunt.this);
progressDialog.setMessage("Page is loading...");
progressDialog.show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
progressDialog.dismiss();
}
},2000);
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句