本文介绍了"装载"消息时启动Android应用程序不消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想,当我的Android显示正在加载...消息。
我设法与下面的code要做到这一点,但问题是,它一直显示正在加载...消息,即使已经被加载页面。当我点击背景消失,但它绝对不是我脑子里想用这个code时。
所以,我想要做的是显示了整整3秒的加载信息的东西。
谁能帮我这个吗?
公共无效onLoadResource(的WebView视图,字符串URL){
如果(progressDialog == NULL){
//在标准情况下YourActivity.this
progressDialog =新ProgressDialog(MainActivity.this);
progressDialog.setMessage(正在加载...);
progressDialog.show();
}
}
公共无效onPageFinished(的WebView视图,字符串URL){
尝试{
如果(progressDialog.isShowing()){
progressDialog.dismiss();
progressDialog = NULL;
}
}赶上(例外的例外){
exception.printStackTrace();
}
}
解决方案
试试这个方法:
webView.setWebChromeClient(新WebChromeClient(){
公共无效onProgressChanged(的WebView观点,诠释进度){
如果(progressDialog == NULL){
progressDialog =新ProgressDialog(MainActivity.this);
progressDialog.setMessage(正在加载...);
progressDialog.show();
} 如果(进度== 100安培;&安培; progressDialog.isShowing()){
progressDialog.dismiss();
progressDialog = NULL;
}
}
});
I would like to show a "loading..." message when my Android .I managed to do this with the code below, but the problem is that it keeps displaying the "Loading..." message, even when the page is already loaded. It disappears when I click on the background, but it's definitely not what I had in mind when using this code.
So what I would like to do is showing a loading message for exactly 3 seconds.
Can anyone help me out with this one?
public void onLoadResource (WebView view, String url) {
if (progressDialog == null) {
// in standard case YourActivity.this
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Loading...");
progressDialog.show();
}
}
public void onPageFinished(WebView view, String url) {
try{
if (progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
}
}catch(Exception exception){
exception.printStackTrace();
}
}
解决方案
Try this way :
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if (progressDialog == null) {
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Loading...");
progressDialog.show();
}
if(progress==100 && progressDialog.isShowing()){
progressDialog.dismiss();
progressDialog = null;
}
}
});
这篇关于"装载"消息时启动Android应用程序不消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!