I have a WebView
in my app with wrap_content
width and height
Before I use webview.loadData
, the width and height of the it was 0, after I load a page (or I use webview.loadData
) , it'll display a web page.
My question is , how can I clear the webview to recover it back to the original state, just as before it loadData
?
Android WebView is a system component for the Android operating system (OS) that allows Android apps to display content from the web directly inside an application.
Add a close button and on its click set: webview. setVisibility(View. INVISIBLE); webview.
If you have only 1 activity you can simply start the service and then call finish() on the activity. However, if you have multiple activities you have to make sure that you close them all (see also this post).
I found this answer, pretty helpful: How do I clear a WebView's content before loading a page?
It is for Cocoa, but basically just call:
webView.loadUrl("about:blank")
The only complete solution is to check for SDK version.
if (Build.VERSION.SDK_INT < 18) { webView.clearView(); } else { webView.loadUrl("about:blank"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With