'How to resolve the white Screen of WebView?
I'm using the below code to populate my WebView with local html files, but it appears fine in some device but recently I noticed in some Device like Colors X114, the WebView appears fine for one Second and then everything disappears and white blank screen appears.
The Code:
package com.nepalpolice.mnemonics;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
/**
* Created by Sagar on 2017/09/23. yo chai menupage ko Fragments ko lagi
*/
public class Homepage extends Fragment {
WebView myWebView;
private LinearLayout container;
private Button nextButton, closeButton;
private EditText findBox;
public Homepage() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_homepage, container, false);
String url = getArguments().getString("url");
myWebView=(WebView)rootView.findViewById(R.id.webview);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
myWebView.getSettings().setLoadsImagesAutomatically(true);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.setInitialScale(1);
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
WebSettings webSettings = myWebView.getSettings();
myWebView.loadUrl(url);
return rootView;
}
public static String changedHeaderHtml(String htmlText) {
String head = "<head><meta name=\"viewport\" content=\"width=device-width, user-scalable=yes\" /></head>";
String closedTag = "</body></html>";
String changeFontHtml = head + htmlText + closedTag;
return changeFontHtml;
}
}
and this is how it appears or should appears
But how it appears in some Device.
and I'm passing the url as string as below
args3.putString("url1", "file:///android_asset/b/dbpm.html");
Solution 1:[1]
You try this:
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAllowContentAccess(true);
settings.setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(url);
Solution 2:[2]
See you have to enable JavaScriptEnabled in it and in url must have http:
wv1.getSettings().setLoadsImagesAutomatically(true);
wv1.getSettings().setJavaScriptEnabled(true);
wv1.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv1.loadUrl(url);
You can take basic information in these links:
Solution 3:[3]
I have a problem with my website. All application requests went to AJAX.
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])')
{//the result is returned to the application}
then I changed the request to
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{//does not return to the application}
The white screen is gone and the app is working.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tung Tran |
| Solution 2 | Dumbo |
| Solution 3 | Alex |


