I'm building a WebView Application for my blog. Everything is running fine, except one thing. The ProgressDialog which appears on the screen while the Homepage is loading, doesn't disappear. Even after the webpage is finished loading.
However, it does go away after tapping the screen twice...........any help would be highly appreciated.
I'm pretty new to Android development so, a little explanation would be helpful with the answer for learning.
Ps Im using
minSdkVersion 21
targetSdkVersion 26
my Java code is:
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = new WebView(this);
webView.setClickable(true);
webView.setFocusableInTouchMode(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");
WebClientClass webViewClient = new WebClientClass();
webView.setWebViewClient(webViewClient);
setContentView(webView);
}
public class WebClientClass extends WebViewClient {
ProgressDialog pd = null;
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
pd = new ProgressDialog(MainActivity.this);
pd.setTitle("Please wait");
pd.setMessage("Page is loading..");
pd.show();
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
pd.dismiss();
}
}
}
my xml code is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webview"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
My App Manifest code is:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.notherstore.notherrstore">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>