简体   繁体   English

无法在WebView中加载网址-黑屏

[英]Unable to load url in webview - black screen

I have been trying a couple of approaches, some found here, to load a url with webview in my app, all so far unsuccessful with one particular page from a client. 我一直在尝试几种方法,在我的应用程序中使用webview加载URL,但到目前为止,对于客户端的一个特定页面,这些方法均无法成功。 Let's for example take this approach: 让我们以这种方式为例:

Main.xml main.xml中

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@drawable/background">
    <RelativeLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:background="@drawable/top_heading"
        android:id="@+id/rlayout1">
        <TextView android:layout_width="wrap_content"
            android:layout_centerVertical="true" android:layout_centerHorizontal="true"
            android:textColor="#ffffff" android:textSize="22dip"
            android:textStyle="bold" android:layout_height="wrap_content"
            android:text="More Information" android:id="@+id/txtviewfbdisplaytitle" />
    </RelativeLayout>
    <RelativeLayout android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_below="@+id/rlayout1"
        android:id="@+id/rlayout2">
        <WebView android:id="@+id/webview1" android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1.0" />
    </RelativeLayout>
</RelativeLayout>

MainActivity.Java MainActivity.Java

public class MainActivity extends Activity {
    private class MyWebViewClient extends WebViewClient {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
              view.loadUrl(url);
              return true;
          }
    }
    Button btnBack;
    WebView webview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        webview=(WebView)findViewById(R.id.webview1);
        webview.setWebViewClient(new MyWebViewClient());
        openURL();
    }

     /** Opens the URL in a browser */
    private void openURL() {
        webview.loadUrl("[see solution]");
        webview.requestFocus();
    }
}

While other websites work, this one won't. 当其他网站正常工作时,该网站将无法工作。 I am fairly new to Android programming. 我是Android编程的新手。 What could I try next? 接下来我可以尝试什么?

Side question: What does the url do differently to prevent a successful load? 附带问题:为了防止成功加载,URL有何不同之处?

The website uses DOM Storage to function and since by default DOM storage is disabled in android webview you have to enable it. 该网站使用DOM存储功能,并且由于默认情况下android webview禁用了DOM存储,因此您必须启用它。

webview.setWebViewClient(new MyWebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
openURL();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM