进度对话框未在WebView中关闭 [英] Progress Dialog not closing in WebView
问题描述
我正在开发一个Android Web应用程序..我创建了一些代码,但面临一个问题。问题是......进度对话框仍然在加载主页后......但是当我点击页面时它就消失了...这个问题只有主页...不在里面..如果我从页面打开另一个链接然后工作完美。我没有在我的手机上测试过..我已经在模拟器上进行了测试......请看一下代码......它有任何需要更改...请建议..这是我的.Java文件
I am developing a Android Web Application.. I have created some code but facing one problem. Problem is that... Progress Dialog is still after loading Homepage... but when I click on page it gone... this problem with Homepage only... not inside.. If I open another link from page then working perfectly.. I have not tested on my Phone.. I have tested it on Emulator Only... and please take a look on the code... it there is any change required... please suggest.. This is my .Java file
package com.aarcreationz.bhajanmala;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity
{
WebView mWeb;
ProgressDialog mProgress;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mWeb = new WebView(this);
mWeb.setClickable(true);
mWeb.setFocusableInTouchMode(true);
setContentView(mWeb);
WebSettings settings = mWeb.getSettings();
settings.setJavaScriptEnabled(true);
mWeb.setWebViewClient(new WebViewClient() {
ProgressDialog mProgress = null;
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
mProgress = new ProgressDialog(MainActivity.this);
mProgress.setTitle("Please Wait!");
mProgress.setMessage("Loading...");
mProgress.show();
}
public void onPageFinished(WebView view, String url) {
if(mProgress.isShowing()) {
mProgress.hide();
mProgress.dismiss();
}
}
});
mWeb.loadUrl("http://www.aarcreationz.com/mala");
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWeb.canGoBack())
{
mWeb.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
这是我的布局文件
}
This is my layout file
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${packageName}.${activityClass}" >
</WebView>
推荐答案
{packageName}。
{packageName}.
{activityClass} >
< / WebView >
{activityClass}" > </WebView>
在手机而不是模拟器中尝试。并选择 mWeb.setWebViewClient(新的WebViewClient(){} 的 @Override 。希望它能正常工作。
Try it in your phone rather than emulator. And pick an @Override of your mWeb.setWebViewClient(new WebViewClient(){} . Hope it will work correctly.
这篇关于进度对话框未在WebView中关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!