admin管理员组文章数量:1430521
For simplicity sake let’s say I have 1 activity that has a few textViews a progressSpinner and a webView.
The webView visibility is set to “gone” all others are set to visible. When the page finishes loading and the 2 divs I want to remove are hidden, I want to hide all visible items and show the fully loaded webView.
However when I run it I see all the visible items and the webView is not showing at this point(which is good). After a few seconds the visible items are gone and a blank webView appears(shouldn’t happen), then the page loads, then the 2 divs are hidden.
I want to hide this from the user how can I set it to display the webView only after the page is pletely done loading and the 2 divs are hidden?
public void onPageFinished(WebView view, String url) {
webview.loadUrl("javascript:$('#MainMenu').hide()");
webview.loadUrl("javascript:$('#EmployeeDashboard').hide()");
android.os.SystemClock.sleep(2500); // My attempt to allow the divs to be hidden before it's displayed to the user
findViewById(R.id.progressSpinner).setVisibility(View.GONE);
findViewById(R.id.imageView1).setVisibility(View.GONE);
findViewById(R.id.textView1).setVisibility(View.GONE);
findViewById(R.id.textView2).setVisibility(View.GONE);
findViewById(R.id.tvLoading).setVisibility(View.GONE);
findViewById(R.id.webview).setVisibility(View.VISIBLE);
}
In the xml I have:
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="gone" />
For simplicity sake let’s say I have 1 activity that has a few textViews a progressSpinner and a webView.
The webView visibility is set to “gone” all others are set to visible. When the page finishes loading and the 2 divs I want to remove are hidden, I want to hide all visible items and show the fully loaded webView.
However when I run it I see all the visible items and the webView is not showing at this point(which is good). After a few seconds the visible items are gone and a blank webView appears(shouldn’t happen), then the page loads, then the 2 divs are hidden.
I want to hide this from the user how can I set it to display the webView only after the page is pletely done loading and the 2 divs are hidden?
public void onPageFinished(WebView view, String url) {
webview.loadUrl("javascript:$('#MainMenu').hide()");
webview.loadUrl("javascript:$('#EmployeeDashboard').hide()");
android.os.SystemClock.sleep(2500); // My attempt to allow the divs to be hidden before it's displayed to the user
findViewById(R.id.progressSpinner).setVisibility(View.GONE);
findViewById(R.id.imageView1).setVisibility(View.GONE);
findViewById(R.id.textView1).setVisibility(View.GONE);
findViewById(R.id.textView2).setVisibility(View.GONE);
findViewById(R.id.tvLoading).setVisibility(View.GONE);
findViewById(R.id.webview).setVisibility(View.VISIBLE);
}
In the xml I have:
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="gone" />
Share
Improve this question
edited Apr 3, 2013 at 5:57
Ken Nichols
asked Apr 3, 2013 at 2:18
Ken NicholsKen Nichols
932 silver badges9 bronze badges
2 Answers
Reset to default 2I assume you're creating your webview object then calling loadUrl(...)
After that, instead of setting the contentView to your webView, set it to your view/graphic/whatever you want to show while it's loading.
In your onPageFinished, call setContentView to your webView.
MyWebView myWebView = new MyWebView();
myWebView.loadUrl ("http://whatever./goes/here");
setContentView(R.loadingurlspinner);
then in your onPageFinished()
//stuff you have above
setContentView(myWebView);
Found out I was having trouble because of a redirect, this helped me: How to listen for a WebView finishing loading a URL?
本文标签: javascriptShow Webview when page completly done loadingStack Overflow
版权声明:本文标题:javascript - Show Webview when page completly done loading? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745542595a2662561.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论