当我点击该按钮时我有按钮我只想显示进度对话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();
}
答案 0 :(得分:1)
您可以使用 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);
}
});