I have searched and found similar questions, but they mostly say how to change the webView content, not how to really hide it.
My webView is initially hidden using android:visibility="gone" in main.xml, I change it dinamically to visible with myWebView.setVisibility(1); when the page is fully loaded (and it works). Now, I want to hide this webView when an error is detected. Reason why I wanted to hide it is because I have a nice background in the layout that informs about the error. I know this is not the best approach to do this, and probably change it later, but now, what I would like to resolve is why the webView is not hidding when an error happens (just for fun, maybe).
This is what I've tried:
@Override
public void onReceivedError (WebView view, int errorCode,
String description, String failingUrl) {
myWebView = (WebView) findViewById(R.id.webview);
// myWebView.setVisibility(0); // Doesn't work!
// if (errorCode == ERROR_TIMEOUT) { // Commented just for trying
try {view.stopLoading();} catch(Exception e){}
try {view.clearView();} catch(Exception e){}
view.loadUrl("file:///android_asset/error.html"); // This Works but I don't want it this way.
view.setBackgroundColor(0x00000000); // Trying to make it transparent. Doesn't work here
view.setVisibility(View.GONE); // Doesn't work. I have tried also with myWebView.
// }
}
Any ideas?