android - Add a Progress Bar in WebView -
i trying add progress/loading bar application uses webview
. confused on how implement progress bar appears every time link clicked.
current code:
public class culearnbrowser extends activity { webview webview; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); webview = (webview) findviewbyid(r.id.webview); webview.setwebviewclient(new hellowebviewclient()); webview.getsettings().setjavascriptenabled(true); webview.loadurl("https://culearn.colorado.edu/webct/entrypageins.dowebct"); } private class hellowebviewclient extends webviewclient { @override public boolean shouldoverrideurlloading(webview view, string url) { view.loadurl(url); return true; } } public boolean onkeydown(int keycode, keyevent event) { if ((keycode == keyevent.keycode_back) && webview.cangoback()) { webview.goback(); return true; } return super.onkeydown(keycode, event); } }
activity layout:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <webview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </linearlayout>
this link may you.
i have added few lines in code , working fine progress bar.
getwindow().requestfeature(window.feature_progress); setcontentview(r.layout.main ); // makes progress bar visible getwindow().setfeatureint( window.feature_progress, window.progress_visibility_on); webview = (webview) findviewbyid(r.id.webview); webview.setwebchromeclient(new webchromeclient() { public void onprogresschanged(webview view, int progress) { //make bar disappear after url loaded, , changes string loading... settitle("loading..."); setprogress(progress * 100); //make bar disappear after url loaded // return app name after finish loading if(progress == 100) settitle(r.string.app_name); } }); webview.setwebviewclient(new hellowebviewclient()); webview.getsettings().setjavascriptenabled(true); webview.loadurl("http://www.google.com");
Comments
Post a Comment