android - Adding ProgressBar into WebView Fragment -
i'm finishing app, simple app contains webview fragments , navigation drawer, ok, don't know how add progress bar while webview loading page, got blank screen before page loads.
here code...
homefragment.java
public class homefragment extends fragment { private webview webview; public homefragment() { // required empty public constructor } @override public void onattach(activity activity) { super.onattach(activity); } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view mainview = (view) inflater.inflate(r.layout.fragment_my_fragment1, container, false); webview webview = (webview)mainview.findviewbyid(r.id.webview); webview.setwebviewclient(new mantenerdominioweb()); webview.getsettings().setjavascriptenabled(true); webview.getsettings().setbuiltinzoomcontrols(false); webview.getsettings().setsupportzoom(false); webview.getsettings().setjavascriptcanopenwindowsautomatically(true); webview.getsettings().setallowfileaccess(true); webview.getsettings().setdomstorageenabled(true); webview.cangoback(); webview.goback(); webview.loadurl("http://www.lfcchile.com/"); return mainview; } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); } @override public void ondestroy() { super.ondestroy(); } @override public void ondetach() { super.ondetach(); } }
my webviewclient class
public class mantenerdominioweb extends webviewclient { private webview webview; public progressbar progressbart4; @override public boolean shouldoverrideurlloading(webview view, string url) { if (uri.parse(url).gethost().endswith("lfcchile.com") || (uri.parse(url).gethost().endswith("thisisanfield.com")) || (uri.parse(url).gethost().endswith("liverpoolecho.co.uk")) || (uri.parse(url).gethost().endswith("liverpoolfc.com"))) { return false; } intent intent = new intent(intent.action_view, uri.parse(url)); view.getcontext().startactivity(intent); return true; } }
and frame xml
<framelayout 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="com.lfcchile.myfragment1"> <!-- todo: update blank fragment layout --> <textview android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="@string/homefrag" /> <webview android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <progressbar android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" android:id="@+id/progressbar1"/> </framelayout>
any ideas please? tried put progressbar "in front" of webview, when page loaded icon doesn't dissapear...
i believe not possible put progressbar because each site has size, difficult measure before finalizing download page.
but can place pre-loader (loading) while page loaded , after end remove access user.
use progressdialog:
public class homefragment extends fragment { private progressdialog progress; private webview webview; public homefragment() { // required empty public constructor } @override public void onattach(activity activity) { super.onattach(activity); } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view mainview = (view) inflater.inflate(r.layout.fragment_my_fragment1, container, false); webview webview = (webview)mainview.findviewbyid(r.id.webview); webview.setwebviewclient(new mantenerdominioweb()); webview.getsettings().setjavascriptenabled(true); webview.getsettings().setbuiltinzoomcontrols(false); webview.getsettings().setsupportzoom(false); webview.getsettings().setjavascriptcanopenwindowsautomatically(true); webview.getsettings().setallowfileaccess(true); webview.getsettings().setdomstorageenabled(true); webview.cangoback(); webview.goback(); webview.loadurl("http://www.lfcchile.com/"); progress = progressdialog.show(this, "aguarde...", "processando sua solicitação.", true); webview.setwebviewclient(new webviewclient() { public void onpagefinished(webview view, string url) { if (progress != null) progress.dismiss(); } }); return mainview; } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); } @override public void ondestroy() { super.ondestroy(); } @override public void ondetach() { super.ondetach(); } }
Comments
Post a Comment